我正在尝试使用 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
我也遇到了同样的麻烦,但是当我将 abc.lib 更改为 abc.lib.a 时,它起作用了,太棒了。 我还有另一个名为 def.lib 的库,它运行良好;但是当我添加.a时,它失败了,太奇怪了!