使用 mingw32 获取'undefined reference to',但使用 mingw64 没有链接器错误,为什么?



我正试图通过在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.lb(解决了这个问题

gendef LeapC.dll //this generates LeapC.def
i686-w64-mingw32-dlltool.exe --def LeapC.def --dllname LeapC.dll --output-lib LeapC.a

最新更新