7

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.

Aaron
  • 1,693
  • 4
  • 26
  • 40

2 Answers2

9

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:

./ssx/genv2.cpp: In function âbool generate_ssqls2(const char*, const ParseV2*)â:
./ssx/genv2.cpp:70:28: error: âstrcmpâ was not declared in this scope

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.

tony gil
  • 9,424
  • 6
  • 76
  • 100
  • 2
    Wow, thanks for taking the time to write up this. I ended up just getting frustrated with it and used the MYSQL C api directly. But I'm sure your solution will help those who also have this problem in the future! – Aaron Oct 12 '12 at 16:42
  • 2
    i had chosen that path originally also, BUT i couldn't catch mysql errors (like attempting to insert a duplicate key entry) and that would make my program abort. so i followed up on where you had left (i benefited from your solution of step 1 [location of lib files]). – tony gil Oct 12 '12 at 18:34
1

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.

Thor
  • 6,607
  • 13
  • 62
  • 96
  • libmysqlclient16 -> This is the one you should install – Jeffrey Vandenborne Jun 01 '12 at 11:47
  • Ok, it says "E: Unable to locate package libmysqlclient16" when I try apt-get install libmysqlclient16. I'm not very familiar with linux, do I need to manually download this? – Aaron Jun 01 '12 at 11:54
  • 1
    Try `apt-cache search mysql` to search for available libs. – Thor Jun 01 '12 at 11:56
  • Thanks for the help! I found libmysqlclient18, but it says it's already the newest version. In fact, libmysqlcppconn-dev (from what you listed) is the only one I didn't already have installed from your list. Running ./configure for mysql++ still gives me that error unfortunately. – Aaron Jun 01 '12 at 12:01
  • Unfortunately I have never done this by myself :-( You have a chance by trying to install some other mysql lib/dev packages ... – Thor Jun 01 '12 at 12:07
  • I appreciate your suggestions. I'll keep looking and see what I can find. – Aaron Jun 01 '12 at 12:11
  • See the edit above, I just pointed to the directory that contains libmysqlclient.so. However, running make now gives me problems :( – Aaron Jun 01 '12 at 17:19