C ++ / mysql连接器 - 未定义的引用get_driver_instance - 已经尝试过的简单的东西 [英] C++ / mysql Connector - undefined reference to get_driver_instance - already tried the easy stuff
问题描述
是的,这个问题之前已经问过...我试过了以前的答案中提到的一切。我的设置真的很直接,所以这不应该这么难。
我只想使用C ++编写针对mysql的程序。我的源代码是从这里的'hello world'类型例子中获取的:
http://dev.mysql.com/doc/refman/5.1/en/connector-cpp-examples-complete-example-1.html
我在Ubuntu 12.10上。我尝试:
g ++ -Wall -o firsttry_prog -I / usr / include / mysqlcppconn -I / usr / local / boost_1_53_0 -L / usr / lib / x86_64-linux-gnu -l:libmysqlclient_r.so.18 -L / usr / lib / mysqlcppconn -lmysqlcppconn firsttry.cpp
它编译(如果我使用-c选项),但不会构建,给我臭名昭着的:
/tmp/ccn768hj.o:在函数`main'中:
firsttry.cpp :(。text + 0x3a):未定义引用`get_driver_instance'
一些细节:
- firsttry.cpp'就是我命名的源代码文件,再次从官方示例中采用verbatem。
- 正如你可以看到我AM连接在 mysqlclient 库和 mysqlcppconn 库。很多时候,这个问题以前被问过,答案是链接这些问题。
- 其他一些历史回答表明示例源代码是错误的,并且该函数需要在sql :: mysql命名空间等等。我很确定源代码是好的。再次,它编译,并改变源代码中的命名空间似乎使情况变得更糟。
感谢您提供任何帮助。
所以我现在有一个星期这个问题,我变得非常沮丧。我只是现在能够最终构建一个程序,除了登录到mysql,我没有什么,我真的发出了欢呼声。这是我有,我希望它有帮助。
我第一次编译c ++连接器库从源,但一段时间后,我想也许我做错了,用于得到它:
sudo apt-get install libmysqlcppconn-dev
这里是我简单的测试程序源文件tester.cpp
code> #include< stdlib.h>
#include< iostream>
#include< mysql_connection.h>
#include< driver.h>
#include< exception.h>
#include< resultset.h>
#include< statement.h>
使用命名空间sql;
int main(void){
sql :: Driver * driver;
sql :: Connection * con;
driver = get_driver_instance();
con = driver-> connect(tcp://127.0.0.1:3306,root,YOURPASSWORD);
return 0;
}
最后g ++编译命令:
sudo g ++ -Wall -I / usr / include / cppconn -o testapp tester.cpp -L / usr / lib -lmysqlcppconn
这对我有用,希望它能帮助你解决你的问题!
Yes this question has been asked before ... I've tried everything mentioned in the previous answers. My setup is really straightforward so this shouldn't be so hard.
I just want to program against mysql using C++. My source code is taken verbatem from the 'hello world' type example here:
http://dev.mysql.com/doc/refman/5.1/en/connector-cpp-examples-complete-example-1.html
I am on Ubuntu 12.10. I am trying:
g++ -Wall -o firsttry_prog -I/usr/include/mysqlcppconn -I/usr/local/boost_1_53_0 -L/usr/lib/x86_64-linux-gnu -l:libmysqlclient_r.so.18 -L/usr/lib/mysqlcppconn -lmysqlcppconn firsttry.cpp
It compiles (if I use -c option) but won't build, giving me the infamous:
/tmp/ccn768hj.o: In function `main': firsttry.cpp:(.text+0x3a): undefined reference to `get_driver_instance'
A few details:
- 'firsttry.cpp' is just what I named the source code file, again taken verbatem from the official example
- As you can see I AM linking in the mysqlclient library and the mysqlcppconn library. Many times when this question has been asked previously, the answer was to link those.
- Some other historical answers suggest the sample source code is wrong and that the function in question needs to be in the sql::mysql namespace etc. I am pretty sure the source code is fine. Again, it compiles, and changing the namespaces in the source code just seems to make it worse.
Thank you in advance for any help you can provide.
So I have now had this problem for a week now and I became very frustrated with it as well. I just now was able to finally build a program that does nothing except login to mysql and I literally squealed with joy. Here is what I have and I hope it helps.
I first compiled the c++ connector library from source but after a while I thought maybe I did something wrong so I then just used apt to get it with:
sudo apt-get install libmysqlcppconn-dev
And here is my simple tester source file "tester.cpp"
#include <stdlib.h>
#include <iostream>
#include <mysql_connection.h>
#include <driver.h>
#include <exception.h>
#include <resultset.h>
#include <statement.h>
using namespace sql;
int main(void){
sql::Driver *driver;
sql::Connection *con;
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306","root","YOURPASSWORD");
return 0;
}
And finally g++ compile command:
sudo g++ -Wall -I/usr/include/cppconn -o testapp tester.cpp -L/usr/lib -lmysqlcppconn
This worked for me and I hope it helps you solve your problem!
这篇关于C ++ / mysql连接器 - 未定义的引用get_driver_instance - 已经尝试过的简单的东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!