链接到Cygwin上使用mingw构建的库

链接到Cygwin上使用mingw构建的库,c,cygwin,mingw,linker-errors,C,Cygwin,Mingw,Linker Errors,我已经在Cygwin上使用mingw构建了libmysqlclient,所以我得到了“.a”文件,但是当我尝试链接这个文件时,它失败了。 我的编译器是mingw,在GNU/Linux上,我的目标是Windows 以下是链接程序的命令行(由automake生成): 以下是链接器错误: mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0x12b): undefined reference to `_mysql_ping@4

我已经在Cygwin上使用mingw构建了libmysqlclient,所以我得到了“.a”文件,但是当我尝试链接这个文件时,它失败了。 我的编译器是mingw,在GNU/Linux上,我的目标是Windows

以下是链接程序的命令行(由automake生成):

以下是链接器错误:

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
,它返回了两个结果,因此该库看起来是有效的

命令i586-mingw32msvc-objdump-x libmysqlclient.a|grep mysql_ping输出
[39](第1节)(fl 0x00)(ty 20)(scl 2)(nx 0)0x000012f0_mysql_ping



这可能很重要:我的GCC目标是I586MIW32 MSVC/

< P>因为您使用C++,您可能需要在MexLCclipse .h中包含MySqclie.h包:

extern“C”{
#包括
}

C++名称损坏可能正在重命名符号,以便链接器无法找到这些符号。

在链接过程中,您可能需要使用
-Wl,--enable stdcall fixup
,以不对修饰的stdcall函数进行链接。大多数库倾向于导出未修饰的符号,即使它们是stdcall


其他要尝试的标志是
-Wl,--kill at
-Wl,--add stdcall alias

您可以发布
objdump-x libmysqlclient.a | grep mysql _ping
的输出吗?您为什么不使用
ar cq libmysqlclient.a App.o ConfigManager.o DialogConfig.o…
?看起来您的命令正在尝试将文件链接在一起,而在创建库时,实际情况并非如此。使用其他库的库有很多未定义的引用,这不是问题mysqlclient.h很可能已经有了。_name@NN模式是微软对stdcall函数的装饰。它似乎不起作用。我将这些参数添加到Makefile.am中的*LDFLAGS中。
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'
extern "C" {
#include <mysqlclient.h>
}