reference to memcpy

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
gedeon

reference to memcpy

Post by gedeon »

Hi , i have the following problem
when i start make for my os project i have this error :
undefined reference to 'memcpy'

but i don't use memcpy

on my old system with gcc 3.2.2 it works fine

with gcc 3.3 it doesn't why ?
maybe the change between this two version is the problem

is there a command option to workarround this problem ?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:reference to memcpy

Post by Pype.Clicker »

GCC may need memcpy to perform language operations like structures copies (i.e. when you have struct stuff=other_stuff;). The easiest workaround is to provide your own memcpy function, for instance with

Code: Select all

static inline void *memcpy(void *dest, const void *src, int n) {
   char *dst=dest; 
   for (;n;n--,dest++,src++)
        *dst=*((char*)src);
    return dest;
}
or any equivalent code you might find smarter (using rep stosb, or using integer moves rather than byte moves when both addresses are aligned on an integer boundary and n>4 ... whatever ...)
gedeon

Re:reference to memcpy

Post by gedeon »

Thanks a lot , it works fine

In order to understand , why the problem appears ?

I have not changed my source code when i have switched my systems. And with GCC 3.2, there was no error.

Does anymore function that i have to provide ?
kaos

Re:reference to memcpy

Post by kaos »

gedeon wrote: Thanks a lot , it works fine

In order to understand , why the problem appears ?

I have not changed my source code when i have switched my systems. And with GCC 3.2, there was no error.

Does anymore function that i have to provide ?
It is hard to say why really. I'd think that both versions would have a memcpy() builtin. Have you changed the command line arguments? Are you building on the same OS with a different compiler or are there other differences? Were the compilers built the same?

Upgrading to a new version of gcc doesn't usually break code; they are pretty good about that sort of thing. In general, gcc is a fantastic compiler.

Gas, on the other hand, is a monstrosity... but I digress.
gedeon

Re:reference to memcpy

Post by gedeon »

The code source didn't change

before
red hat 9, kdevelop 2.1.5, gcc 3.2.2

after
Suse 8.2 , kdevelop 2.1.5, gcc 3.3

strange !!!
Post Reply