Initialize array in gcc, undefined reference to `memcpy '

I am coding C in Nachos3.4, Centos 6.0, compiling gcc 2.95.3,

the command line I'm using is gmake all

when i compile this everything is fine

int main()
    char* fname[] = {"c(0)", "c(1)", "c(2)", "c(3)", "c(4)", "c(5)", "c(6)", "c(7)"};
    return 0;


but when i do it he said undefined reference to 'memcpy'

int main()
    char* fname[] = {"c(0)", "c(1)", "c(2)", "c(3)", "c(4)", "c(5)", "c(6)", "c(7)", "c(8)"};
    return 0;


where is the problem and how can i fix it?


source to share

1 answer

Your automatic array initialization fname

involves the compiler making a copy of a large amount of data from the hidden array static

into your array on the stack. GCC has several methods it can use to do this, one of its favorites is the C library subroutine call memcpy

, as it should be nice and fast no matter what happens.

In your case, you don't have a C library, so this is a problem.

You can tell that GCC always uses x86 instructions rather than calling the library like this:

gcc -mstringop-strategy=rep_byte -c -O file.c



gcc -mstringop-strategy=loop -c -O file.c


However, I got the impression that GCC didn't start doing this until it was in the middle of 3.x.

Perhaps you are using a MIPS processor, instructors such as this processor, in which the required parameter will be -mno-memcpy




All Articles