使用 mingw32 获取 'undefined reference to',但使用 mingw64 没有链接器错误,为什么?
Getting 'undefined reference to' using mingw32, but no linker error using mingw64, why?
我正在尝试通过在 cygwin 上使用 mingw 为 LeapMotion API 编译示例
当我用 mingw64 编译时,它工作正常:
x86_64-w64-mingw32-g++ -s -I ../include -L ../lib/x64/ ExampleConnection.cpp -lLeapC PollingSample.cpp -oPollingSample
但如果我切换到 32 位:
i686-w64-mingw32-g++ -s -I ../include -L ../lib/x86/ ExampleConnection.cpp -lLeapC PollingSample.cpp -oPollingSample
我得到:
/usr/lib/gcc/i686-w64-mingw32/10/../../../../i686-w64-mingw32/bin/ld: /tmp/ccg2UNs3.o:ExampleConnection.cpp:(.text+0x31): undefined reference to `LeapCreateConnection'
/usr/lib/gcc/i686-w64-mingw32/10/../../../../i686-w64-mingw32/bin/ld: /tmp/ccg2UNs3.o:ExampleConnection.cpp:(.text+0x52): undefined reference to `LeapOpenConnection'
/usr/lib/gcc/i686-w64-mingw32/10/../../../../i686-w64-mingw32/bin/ld: /tmp/ccg2UNs3.o:ExampleConnection.cpp:(.text+0xb5): undefined reference to `LeapCloseConnection'
/usr/lib/gcc/i686-w64-mingw32/10/../../../../i686-w64-mingw32/bin/ld: /tmp/ccg2UNs3.o:ExampleConnection.cpp:(.text+0xe7): undefined reference to `LeapDestroyConnection'
/usr/lib/gcc/i686-w64-mingw32/10/../../../../i686-w64-mingw32/bin/ld: /tmp/ccg2UNs3.o:ExampleConnection.cpp:(.text+0xfd): undefined reference to `LeapDestroyConnection'
/usr/lib/gcc/i686-w64-mingw32/10/../../../../i686-w64-mingw32/bin/ld: /tmp/ccg2UNs3.o:ExampleConnection.cpp:(.text+0x16a): undefined reference to `LeapOpenDevice'
/usr/lib/gcc/i686-w64-mingw32/10/../../../../i686-w64-mingw32/bin/ld: /tmp/ccg2UNs3.o:ExampleConnection.cpp:(.text+0x1d2): undefined reference to `LeapGetDeviceInfo'
/usr/lib/gcc/i686-w64-mingw32/10/../../../../i686-w64-mingw32/bin/ld: /tmp/ccg2UNs3.o:ExampleConnection.cpp:(.text+0x205): undefined reference to `LeapGetDeviceInfo'
/usr/lib/gcc/i686-w64-mingw32/10/../../../../i686-w64-mingw32/bin/ld: /tmp/ccg2UNs3.o:ExampleConnection.cpp:(.text+0x26d): undefined reference to `LeapCloseDevice'
/usr/lib/gcc/i686-w64-mingw32/10/../../../../i686-w64-mingw32/bin/ld: /tmp/ccg2UNs3.o:ExampleConnection.cpp:(.text+0x4ac): undefined reference to `LeapPollConnection'
collect2: error: ld returned 1 exit status
我尝试更改命令字符串中 -lLeapC 的位置,并反转 .cpp 文件的顺序,但我总是得到相同的错误。
我通过在 /lib/x86/ 中将 LeapC.lib 转换为 LeapC.a 解决了这个问题(并从文件夹中删除了 LeapC.lib)
gendef LeapC.dll //this generates LeapC.def
i686-w64-mingw32-dlltool.exe --def LeapC.def --dllname LeapC.dll --output-lib LeapC.a
我正在尝试通过在 cygwin 上使用 mingw 为 LeapMotion API 编译示例
当我用 mingw64 编译时,它工作正常:
x86_64-w64-mingw32-g++ -s -I ../include -L ../lib/x64/ ExampleConnection.cpp -lLeapC PollingSample.cpp -oPollingSample
但如果我切换到 32 位:
i686-w64-mingw32-g++ -s -I ../include -L ../lib/x86/ ExampleConnection.cpp -lLeapC PollingSample.cpp -oPollingSample
我得到:
/usr/lib/gcc/i686-w64-mingw32/10/../../../../i686-w64-mingw32/bin/ld: /tmp/ccg2UNs3.o:ExampleConnection.cpp:(.text+0x31): undefined reference to `LeapCreateConnection'
/usr/lib/gcc/i686-w64-mingw32/10/../../../../i686-w64-mingw32/bin/ld: /tmp/ccg2UNs3.o:ExampleConnection.cpp:(.text+0x52): undefined reference to `LeapOpenConnection'
/usr/lib/gcc/i686-w64-mingw32/10/../../../../i686-w64-mingw32/bin/ld: /tmp/ccg2UNs3.o:ExampleConnection.cpp:(.text+0xb5): undefined reference to `LeapCloseConnection'
/usr/lib/gcc/i686-w64-mingw32/10/../../../../i686-w64-mingw32/bin/ld: /tmp/ccg2UNs3.o:ExampleConnection.cpp:(.text+0xe7): undefined reference to `LeapDestroyConnection'
/usr/lib/gcc/i686-w64-mingw32/10/../../../../i686-w64-mingw32/bin/ld: /tmp/ccg2UNs3.o:ExampleConnection.cpp:(.text+0xfd): undefined reference to `LeapDestroyConnection'
/usr/lib/gcc/i686-w64-mingw32/10/../../../../i686-w64-mingw32/bin/ld: /tmp/ccg2UNs3.o:ExampleConnection.cpp:(.text+0x16a): undefined reference to `LeapOpenDevice'
/usr/lib/gcc/i686-w64-mingw32/10/../../../../i686-w64-mingw32/bin/ld: /tmp/ccg2UNs3.o:ExampleConnection.cpp:(.text+0x1d2): undefined reference to `LeapGetDeviceInfo'
/usr/lib/gcc/i686-w64-mingw32/10/../../../../i686-w64-mingw32/bin/ld: /tmp/ccg2UNs3.o:ExampleConnection.cpp:(.text+0x205): undefined reference to `LeapGetDeviceInfo'
/usr/lib/gcc/i686-w64-mingw32/10/../../../../i686-w64-mingw32/bin/ld: /tmp/ccg2UNs3.o:ExampleConnection.cpp:(.text+0x26d): undefined reference to `LeapCloseDevice'
/usr/lib/gcc/i686-w64-mingw32/10/../../../../i686-w64-mingw32/bin/ld: /tmp/ccg2UNs3.o:ExampleConnection.cpp:(.text+0x4ac): undefined reference to `LeapPollConnection'
collect2: error: ld returned 1 exit status
我尝试更改命令字符串中 -lLeapC 的位置,并反转 .cpp 文件的顺序,但我总是得到相同的错误。
我通过在 /lib/x86/ 中将 LeapC.lib 转换为 LeapC.a 解决了这个问题(并从文件夹中删除了 LeapC.lib)
gendef LeapC.dll //this generates LeapC.def
i686-w64-mingw32-dlltool.exe --def LeapC.def --dllname LeapC.dll --output-lib LeapC.a