我正在尝试使用 MySQL C++ 连接器库编译一段相当简单的代码。我将库静态链接到我的应用程序。
g++ "./source/main.cpp" -std=c++11 -m64 -static -pthread -lmysqlcppconn -lboost_system -lboost_filesystem -lfastcgipp -lboost_thread -lboost_date_time -o "/var/www/index.fcgi"
然而,当我执行这个命令来编译程序时,我留下了数百个undefined reference to ...
错误。几个例子:
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::affected_rows(st_mysql*)':
(.text+0x164): undefined reference to `mysql_affected_rows'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::autocommit(st_mysql*, char)':
(.text+0x18d): undefined reference to `mysql_autocommit'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libmysqlcppconn.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::close(st_mysql*)':
(.text+0x1ac): undefined reference to `mysql_close'
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
collect2: error: ld returned 1 exit status
当我链接库是动态链接时,一切正常。
如何静态链接这个库?