Setting up Mysql++ in linux

匿名 (未验证) 提交于 2019-12-03 02:52:02

问题:

I want to connect to a mysql database with C++ in linux. On my local machine I am running Ubuntu, and installed the mysql server and client packages:

sudo apt-get install mysql-server mysql-client

I came across Mysql++ but have some problems when running ./configure from their binary package. The error says:

checking for MySQL library directory... configure: error: Didn't find mysqlclient library in '/usr/lib64 /usr/lib /usr/lib64/mysql /usr/lib/mysql /usr/local/lib64 /usr/local/lib /usr/local/lib/mysql /usr/local/mysql/lib /usr/local/mysql/lib/mysql /usr/mysql/lib/mysql /opt/mysql/lib /opt/mysql/lib/mysql /sw/lib /sw/lib/mysql'

I see where I can use this command to specify the path:

./configure --with-mysql-lib=/...

but I do not know where to point it to. I used whereis mysql but cannot find any mysql directory that contains a lib subdirectory. Where would the mysqlclient libraries be installed?


EDIT:

After doing locate libmysqlclient I got back

/usr/lib/i386-linux-gnu/libmysqlclient.so.18
/usr/lib/i386-linux-gnu/libmysqlclient.so.18.0.0
/usr/lib/i386-linux-gnu/libmysqlclient_r.so.18
/usr/lib/i386-linux-gnu/libmysqlclient_r.so.18.0.0
/usr/share/doc/libmysqlclient18
/usr/share/doc/libmysqlclient18/changelog.Debian.gz
/usr/share/doc/libmysqlclient18/copyright
/var/cache/apt/archives/libmysqlclient18_5.5.22-0ubuntu1_i386.deb
/var/lib/dpkg/info/libmysqlclient18:i386.list
/var/lib/dpkg/info/libmysqlclient18:i386.md5sums
/var/lib/dpkg/info/libmysqlclient18:i386.postinst
/var/lib/dpkg/info/libmysqlclient18:i386.postrm
/var/lib/dpkg/info/libmysqlclient18:i386.shlibs

So, I tried ./configure --with-mysql-lib=/usr/lib/i386-linux-gnu and it seems to complete without any complaining.

Although this solves the problem of getting ./configure to complete, I still have further troubles. When I run make things go fine until this point:

In file included from ./lib/sql_buffer.h:31:0, from ./lib/sql_buffer.cpp:26: ./lib/refcounted.h:258:2: error: ‘size_t’ does not name a type ./lib/refcounted.h: In constructor ‘mysqlpp::RefCountedPointer::RefCountedPointer()’: ./lib/refcounted.h:89:2: error: class ‘mysqlpp::RefCountedPointer’ does not have any field named ‘refs_’ ./lib/refcounted.h: In constructor ‘mysqlpp::RefCountedPointer::RefCountedPointer(T*)’: ./lib/refcounted.h:100:2: error: class ‘mysqlpp::RefCountedPointer’ does not have any field named ‘refs_’ ./lib/refcounted.h:104:4: error: ‘refs_’ was not declared in this scope ./lib/refcounted.h:104:16: error: expected type-specifier before ‘size_t’ ./lib/refcounted.h:104:16: error: expected ‘;’ before ‘size_t’ ./lib/refcounted.h: In constructor ‘mysqlpp::RefCountedPointer::RefCountedPointer(const ThisType&)’: ./lib/refcounted.h:112:2: error: class ‘mysqlpp::RefCountedPointer’ does not have any field named ‘refs_’ ./lib/refcounted.h:115:8: error: ‘refs_’ was not declared in this scope ./lib/refcounted.h: In destructor ‘mysqlpp::RefCountedPointer::~RefCountedPointer()’: ./lib/refcounted.h:125:7: error: ‘refs_’ was not declared in this scope ./lib/refcounted.h: In member function ‘void mysqlpp::RefCountedPointer::swap(mysqlpp::RefCountedPointer::ThisType&)’: ./lib/refcounted.h:246:13: error: ‘refs_’ was not declared in this scope make: *** [mysqlpp_sql_buffer.o] Error 1

I'm not really familiar with C++, so I'm not sure what the error means exactly. Any help or direction on how to get Mysql++ setup from this point would be much appreciated. Although, I admit that I'm also starting to look for alternative libraries to use.

回答1:

this problem is caused because size_t depends on the inclusion of stddef namespace before it is called in the configuration (make) files.

i had the very same problem (using an amazon EC2 ubuntu 12.04 cloud server) and solved it by editing the offending file (sql_buffer.cpp located, in my case, /home/ubuntu/mysql++-3.1.0/lib) and including stddef (while also moving string namespace up):

#include <stddef.h> #include <string.h> #include "sql_buffer.h" 

your question is answered with this correction. BUT, you might have additional problems, like i did. so i explain how i solved some subsequent problems, which you might or might not have also.

you might have to use

sudo chown username sql_buffer.cpp 

to be able to edit the file, depending on how your install is setup (i am user ubuntu, for example).

i then bumped into another problem:

so i edited the offending file (genv2.cpp) and included string namespace

#include <string.h> 

then i had ANOTHER problem with:

./libmysqlpp_ssqls2parse.a(ssqls2parse_parsev2.o): In function `Type': /home/ubuntu/mysql++-3.1.0/./ssx/parsev2.cpp:256: undefined reference to `mysqlpp::internal::str_to_lwr 

i could have edited Makefile.in but chose to simply run in command line:

sudo  g++ -o test_ssqls2 test_ssqls2_ssqls2.o -lmysqlpp_ssqls2parse   -L. -lmysqlclient   -L/usr/lib/x86_64-linux-gnu  -lmysqlpp 

i then continued the make process.

that worked for me: mysql++ installed and running.



回答2:

You need to install the header (dev) files, I assume one of these:

apt-cache search mysql ... libmysqlclient-dev - MySQL database development files libmysqlclient16 - MySQL database client library libmysql++-dev - MySQL C++ library bindings (development) libmysqlcppconn-dev - MySQL Connector for C++ (development files) ... 

--with-mysql-lib should not be necessary because the files will be installed in the default locations.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!