我在Cygwin上使用mingw构建了libmysqlclient,所以我得到了“.a”文件,但是当我尝试链接这个文件时,它失败了。 我的编译器是mingw,在GNU / Linux上,我的目标是Windows。
这是链接程序的命令行(由automake生成):
i586-mingw32msvc-g++ -s -O1 -Wall -Wclobbered -Wempty-body -Wignored-qualifiers -Wmissing-field-initializers -Wsign-compare -Wtype-limits -Wuninitialized -mwindows -o .libs/valoisscan.exe App.o ConfigManager.o DialogConfig.o DialogRCDStart.o DialogAbout.o findFile.o MainFrame.o PanelScan.o PanelSearch.o MyException.o strWxStdConv.o libsqlendive.o PanelBase.o rc.o -mthreads -Wl,--subsystem -Wl,windows -mwindows -L/usr/i586-mingw32msvc//lib /usr/i586-mingw32msvc//lib/libwx_mswu_richtext-2.8.a /usr/i586-mingw32msvc//lib/libwx_mswu_aui-2.8.a /usr/i586-mingw32msvc//lib/libwx_mswu_xrc-2.8.a /usr/i586-mingw32msvc//lib/libwx_mswu_qa-2.8.a /usr/i586-mingw32msvc//lib/libwx_mswu_html-2.8.a /usr/i586-mingw32msvc//lib/libwx_mswu_adv-2.8.a /usr/i586-mingw32msvc//lib/libwx_mswu_core-2.8.a /usr/i586-mingw32msvc//lib/libwx_baseu_xml-2.8.a /usr/i586-mingw32msvc//lib/libwx_baseu_net-2.8.a /usr/i586-mingw32msvc//lib/libwx_baseu-2.8.a -lwxregexu-2.8 -lwxexpat-2.8 -lwxtiff-2.8 -lwxjpeg-2.8 -lwxpng-2.8 -lwxzlib-2.8 -lrpcrt4 -loleaut32 -lole32 -luuid -lwinspool -lwinmm -lshell32 -lcomctl32 -lcomdlg32 -lctl3d32 -ladvapi32 -lwsock32 -lgdi32 ticpp/.libs/libticpp.a mysqlwrapped/.libs/libmysqlwrapped.a -lmysqlclient -lstdc++ -mthreads
以下是链接器错误:
mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0x12b): undefined reference to `_mysql_ping@4'
mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0x17b): undefined reference to `_mysql_errno@4'
mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0x1d5): undefined reference to `_mysql_error@4'
mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0x2f0): undefined reference to `_mysql_num_rows@4'
mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0x31e): undefined reference to `_mysql_insert_id@4'
mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0x349): undefined reference to `_mysql_fetch_row@4'
mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0x3bd): undefined reference to `_mysql_query@8'
mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0x5da): undefined reference to `_mysql_free_result@4'
mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0xb8c): undefined reference to `_mysql_free_result@4'
mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0xd9c): undefined reference to `_mysql_free_result@4'
mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0x1712): undefined reference to `_mysql_store_result@4'
mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0x172b): undefined reference to `_mysql_fetch_field@4'
mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0x1962): undefined reference to `_mysql_fetch_field@4'
mysqlwrapped/.libs/libmysqlwrapped.a(Database.o):Database.cpp:(.text+0x3c2): undefined reference to `_mysql_options@12'
mysqlwrapped/.libs/libmysqlwrapped.a(Database.o):Database.cpp:(.text+0x129c): undefined reference to `_mysql_init@4'
mysqlwrapped/.libs/libmysqlwrapped.a(Database.o):Database.cpp:(.text+0x135d): undefined reference to `_mysql_real_connect@32'
mysqlwrapped/.libs/libmysqlwrapped.a(Database.o):Database.cpp:(.text+0x1405): undefined reference to `_mysql_real_connect@32'
mysqlwrapped/.libs/libmysqlwrapped.a(Database.o):Database.cpp:(.text+0x14c0): undefined reference to `_mysql_ping@4'
mysqlwrapped/.libs/libmysqlwrapped.a(Database.o):Database.cpp:(.text+0x155a): undefined reference to `_mysql_ping@4'
mysqlwrapped/.libs/libmysqlwrapped.a(Database.o):Database.cpp:(.text+0x15eb): undefined reference to `_mysql_close@4'
mysqlwrapped/.libs/libmysqlwrapped.a(Database.o):Database.cpp:(.text+0x1ad9): undefined reference to `_mysql_close@4'
mysqlwrapped/.libs/libmysqlwrapped.a(Database.o):Database.cpp:(.text+0x1e1b): undefined reference to `_mysql_close@4'
我尝试了strings libmysqlclient.a | grep _mysql_ping
并返回了两个结果,因此lib看起来有效。
命令i586-mingw32msvc-objdump -x libmysqlclient.a | grep mysql_ping
输出[ 39](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x000012f0 _mysql_ping
可能很重要:我的gcc目标是i586-mingw32msvc
答案 0 :(得分:1)
由于您使用的是C ++,因此可能需要将mysqlclient.h包含在extern“C”中:
extern "C" {
#include <mysqlclient.h>
}
C ++名称重整可能会重命名符号,因此链接器无法找到它们。
答案 1 :(得分:1)
您可能需要在链接期间使用-Wl,--enable-stdcall-fixup
以不链接装饰的stdcall函数。大多数图书馆都倾向于输出未修饰的符号,即使它们是stdcall。
要尝试的其他标志是-Wl,--kill-at
和-Wl,--add-stdcall-alias
。