我正在使用MinGW。我有一些调用malloc和一些其他通用函数的代码。当我输入:MinGW未定义的引用malloc,free,sprintf,_beginthreadex
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'
我假设这是我如何调用该链接的问题。因此,如果不清楚问题是什么,我只会发布代码。我希望这是一个简单的解决方法,并且我简单地在链接时忘记了包含一些超级明显的库。
可能重复[使用MinGW编译器时发生链接错误(无法找到__main)](http://stackoverflow.com/questions/4981826/link-error-while-using-mingw-compiler-cant-find-主) – 2012-03-14 03:25:29