用 C 语言编译:未定义对"memcpy"的引用



我正在做一个关于玉米片的学校项目,我收到了一些奇怪的错误。你可以在这里看到我的代码:只是c文件,如果你需要更多的

,请告诉我控制台的输出如下所示:
../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

在我的整个Nachos项目文件夹中,没有一个单一的调用'memcpy'(我在文件搜索中使用括号查找)。

这是第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;
}

您应该使用gcc链接,而不是ld

当您通过gcc链接时,它将系统库提供给ld。如果你通过ld链接,你必须自己指定所有这些,以及一堆其他的东西。

最新更新