未定义的引用'get_driver_instance' [英] undefined reference to 'get_driver_instance'

查看:887
本文介绍了未定义的引用'get_driver_instance'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到未定义的引用'get_driver_instance'当构建最简单的例子从: http://dev.mysql.com/doc/refman/5.1/en/connector-cpp-examples-complete-example-1.html < a>。它在我的本地机器上构建和运行良好,但不会在服务器上构建 - 似乎链接mysql库问题。

这是我的构建cmd:

g ++ -o test -Iinclude -Llib -L ​​/ usr / lib64 / mysql main.cpp

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

我无法在服务器上运行本地构建的二进制文件,因为它是使用动态'libmysqlclient 。所以'。我也试图在我的本地机器上安装静态libmysqlclient.a,但我找不到'libmysqlclient.a'在我的/ usr / lib / mysql dir。我假设只有在服务器上运行它的方式是如果我可以静态地在我的本地机器上,或者我可以编译和直接在服务器上构建它。我试过'sudo yum安装mysql-devel',但我只看到libmysqlclient.so - 找不到'libmysqlclient.a'。有没有办法在我的本地linux上安装一个静态mysqlclient或是我的构建cmd错误?如何在服务器上构建源代码?

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?

推荐答案

尝试添加 -lmysqlcppconn 链接器选项。我回答只是为了有一个答案(即使这是在2年前问:D)

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)

这篇关于未定义的引用'get_driver_instance'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆