用C编译: undefined reference to `memcpy'

标签 c gcc ld nachos

我正在与 Nachos 一起开展一个学校项目,并且收到一些奇怪的错误。您可以在这里看到我的代码:just the c file, lemme know if you need more

控制台的输出如下所示:

../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 链接,则必须自己指定所有内容以及一堆其他内容。

关于用C编译: undefined reference to `memcpy' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33161509/

相关文章:

c++ - 如何将立即数 4 位值传递给 _mm256_blend_pd 的最后一个参数

c - 如何在 CMake 中使用特定的链接脚本(*.lds)?

linux - 加载警告 : cannot find entry symbol _start

c - 与 "ld"链接时出现以下错误?

c - OpenGL 默认帧缓冲区内容在最小化/恢复周期后消失了吗?

c - 如何正确使用 libsodium 以使其在版本之间兼容?

c - 如何使用 yacc 从 char 数组中解析?

C 程序在一个系统上编译和运行,而不是在另一个系统上

gcc - 使用python3安装matplotlib时gcc出错

c - 生成 10 个随机字符