简体   繁体   中英

undefined reference to 'get_driver_instance'

I'm getting "undefined reference to 'get_driver_instance'" when building even the most simple example from: http://dev.mysql.com/doc/refman/5.1/en/connector-cpp-examples-complete-example-1.html . It builds and runs fine on my local machine but it won't build on the server – seems like linking mysql library issue.
This is my build cmd:
g++ -o test -Iinclude -Llib -L/usr/lib64/mysql main.cpp

I can't run the local built binary on the server as it was built using dynamic 'libmysqlclient.so'. I also tried to install the static libmysqlclient.a on my local machine but I can't find 'libmysqlclient.a' in my /usr/lib/mysql dir. I assume Only way to run it on the server is if I can either build it statically on my local machine or I can compile and build it directly on the server. I tried 'sudo yum install mysql-devel' but I only see libmysqlclient.so -- can't find 'libmysqlclient.a'. Is there a way to install a static mysqlclient on my local linux or is my build cmd wrong? How can I build source code on the server?

try adding -lmysqlcppconn to your linker options. I answered just for this to have an answer (even though this was asked 2 years ago :D)

尝试在命令中添加'-lmysqlclient',即:g ++ -o test -Iinclude -Llib -L ​​/ usr / lib64 / mysql -lmysqlclient main.cpp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM