使用包含对i686-w64-mingw32-gcc
的调用的CMake链接c源文件时,我从Sleep()
收到错误(请参阅主题)。我想知道解决问题的原因。
这是编译器的调用:
/usr/bin/i686-w64-mingw32-gcc -g @CMakeFiles/MQTTAsync_publish.dir/includes_C.rsp -o CMakeFiles/MQTTAsync_publish.dir/src/samples/MQTTAsync_publish.c.obj -c /tmp/org.eclipse.paho.mqtt.c/src/samples/MQTTAsync_publish.c
归档者:
/usr/bin/i686-w64-mingw32-ar cr CMakeFiles/MQTTAsync_publish.dir/objects.a @CMakeFiles/MQTTAsync_publish.dir/objects1.rsp
链接器:
/usr/bin/i686-w64-mingw32-gcc -g -fdata-sections -ffunction-sections -Wl,--enable-stdcall-fixup -static-libgcc -Wl,--whole-archive CMakeFiles/MQTTAsync_publish.dir/objects.a -Wl,--no-whole-archive -o MQTTAsync_publish.exe -Wl,--out-implib,libMQTTAsync_publish.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles/MQTTAsync_publish.dir/linklibs.rsp
`_Sleep' referenced in section `.text' of CMakeFiles/MQTTAsync_publish.dir/objects.a(MQTTAsync_publish.c.obj): defined in discarded section `.text' of /usr/lib/gcc/i686-w64-mingw32/4.9-win32/../../../../i686-w64-mingw32/lib/../lib/libkernel32.a(libkernel32s01140.o)
这些是链接器响应文件的内容:
libpaho-mqtt3a.dll.a -lpthread -lws2_32 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
最小化工作样本:
main.c中:
#include <windows.h>
int main(void)
{
Sleep(10);
return 0;
}
编译器/链接器调用:
i686-w64-mingw32-gcc -static-libgcc -lpthread -lws2_32 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -o main.exe main.c
这里没问题。
答案 0 :(得分:0)
令人难以置信,我在最初提到的C文件中只需要#include <windows.h>
,并且没有任何麻烦。