【发布时间】:2012-03-30 12:33:35
【问题描述】:
我正在使用 MinGW。我有一些调用 malloc 和其他一些通用函数的代码。当我输入时:
gcc TestCode.c
我得到一个 a.exe 文件,它运行良好,而且我没有收到任何警告。
如果我输入这个:
gcc -c TestCode.c -o TestCode.o
ld *.o
我收到一大堆警告,例如:
TestCode.o:TestCode.c:(.text+0xa): undefined reference to `__main'
TestCode.o:TestCode:(.text+0x2e): undefined reference to `printf'
TestCode.o:TestCode:(.text+0x42): undefined reference to `_strerror'
TestCode.o:TestCode:(.text+0x69): undefined reference to `snprintf'
TestCode.o:TestCode:(.text+0x7e): undefined reference to `malloc'
TestCode.o:TestCode:(.text+0x93): undefined reference to `_strerror'
TestCode.o:TestCode:(.text+0xb1): undefined reference to `sprintf'
TestCode.o:TestCode:(.text+0xcf): undefined reference to `free'
我假设这是我如何调用链接器的问题。因此,如果不清楚问题是什么,我只会发布代码。我希望这是一个简单的解决方法,并且我只是忘记在链接时包含一些非常明显的库。
【问题讨论】: