开发者

Link to a library built with mingw on Cygwin

I have built libmysqlclient using mingw on Cygwin, so I get the ".a" file, but when I try to link with this file, it fails. My compiler is mingw, on GNU/Linux and I target Windows.

Here is the command line to link the program (generated by 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

Here are the linker errors :

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'

I tried strings libmysqlclient.a | grep _mysql_ping and it returned two results, so the lib looks valid.

Command i586-mingw32msvc-objdump -x libmysqlclient.a | grep mysql_ping outputs [ 39](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x000012f0 _mysql_ping


It might be important : my target for gcc is i586-mingw32msvc


Since you are using C++ you might need to wrap your inclusion of mysqlclient.h in an extern "C":

extern "C" {
#include <mysqlclient.h>
}

C++ name mangling might be renaming the symbols so they can't be found by the linker.


You might need to use -Wl,--enable-stdcall-fixup during linking to not link against the decorated stdcall functions. Most libraries tend to export undecorated symbols even though they are stdcall.

Other flags to try are -Wl,--kill-at and -Wl,--add-stdcall-alias.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜