Search code examples
cgccldnachos

Compiling in C: undefined reference to `memcpy'


I am working on a school project with Nachos and I am receiving some strange error. You can see my code here: just the c file, lemme know if you need more

The output from the console looks like this:

../gnu/gcc -G 0 -c -I../userprog -I../threads -I../machine -c threadtest.c
../gnu/ld -T newscript -N start.o threadtest.o -o threadtest.coff
threadtest.o: In function `CreateClerk':
threadtest.c:804: undefined reference to `memcpy'
threadtest.o: In function `ApplicationClerkNoCustomerAtRegister':
threadtest.c:902: undefined reference to `memcpy'
threadtest.c:902: undefined reference to `memcpy'
threadtest.c:902: undefined reference to `memcpy'
threadtest.o: In function `PictureClerkNoCustomerAtRegister':
threadtest.c:954: undefined reference to `memcpy'
threadtest.o:threadtest.c:954: more undefined references to `memcpy' follow
gmake: *** [threadtest] Error 1

In my entire Nachos project folder there isn't one single call to 'memcpy' (I did a find in files search with Brackets).

Here is line 804+:

struct Clerk CreateClerk(char* _name, int _number, struct PassportOffice* _theOffice, struct Line* theLine) {
    struct Clerk theClerk;
    theClerk.name = _name;
    theClerk.number = _number;
    theClerk.theOffice = _theOffice;
    theClerk.myLine = theLine;
    LineSetClerk(theClerk.myLine,&theClerk);
    theClerk.dataLock = CreateLock("dataLock",8);
    theClerk.myBribeCV = CreateCV("myBribeCV",9);
    theClerk.breakCV = CreateCV("breakCV",7);
    theClerk.breakLock = CreateLock("breakLock",9);
    theClerk.walkUpCV = CreateCV("walkUpCV",8);
    return theClerk;
}

Solution

  • You should use gcc to link, not ld.

    When you link via gcc it supplies the system libraries to ld . If you link via ld you have to specify all that yourself, and a pile of other things.