How I got MySQL Connector to compile statically on Debian

I spent an entire day getting the flags right, mostly because I didn't know about some of them. This is here as a reference to others just starting out and wanting to play with the MySQL Connector/C++ wrapper with the client included and statically linked.

This was done on Debian 7 64-bit and 32-bit.
I ended up installing the dev packages from the repo and statically linking them.
 
apt-get install libmysqlcppconn-dev libmysqlclient-dev


If main.cpp is your only file then this is how to compile statically:
 
g++ -static main.cpp -lmysqlcppconn -lmysqlclient -lz -ldl -pthread

There are some warnings about glibc and shared libraries, but no errors.

Here is a link to the MySQL example file I used as main.cpp:
http://dev.mysql.com/doc/connector-cpp/en/connector-cpp-examples-complete-example-1.html

Note: The wrapper also needs libboost-dev. Install it if you don't have it.
Last edited on
Nice work.

Debian has aptitude, and your installation only needed to be:
$ sudo aptitude install libmysqlcppconn-dev

It probably would have installed boost-dev as well.

POSIX operating systems typically have an executable named pkg-config, you may have gotten away with linking your program with:
$ g++ -static main.cpp `pkg-config --libs mysqlcppconn`

And note that those are backticks, not single quotes.

It is actually somewhat likely that pkg-config will not find mysqlccppconn because packages often name the pkg-config command different than the library name.

Chances are however, that the following command would make a list of possible names, and I imagine you are capable at finding the package you just installed in that list:
$ pkg-config --list-all | grep sql
Thanks.

For me, pkg-config has suspiciously few packages in its list; the only *sql* is sqlite3.
In fact, searching my filesystem for *.pc turns up not a whole lot.

Anyway, here's a link about writing pkg-config files- for reference and those interested, and also because I didn't know about it:
http://people.freedesktop.org/~dbn/pkg-config-guide.html
Topic archived. No new replies allowed.