Syntax_Error
Syntax_Error

Reputation: 6220

Adding compilation flags to Qt to use mysql

I am using ubuntu to build a project that uses mysql. To compile the project from the command line I use the following flags:

$(mysql_config --cflags)$(mysql_config --libs)

However, when I am trying to build from Qt, I get that undefined reference to mysql_close and the rest of mysql connection functions.

I tried adding the representation of the previous command line flags to QMAKe in Qt and still same errors.

Any Help?

Upvotes: 1

Views: 575

Answers (3)

Nikos C.
Nikos C.

Reputation: 51840

Add the output of "mysql_config --cflags" to the compiler flags with:

QMAKE_CFLAGS += $$system(mysql_config --cflags)
QMAKE_CXXFLAGS += $$system(mysql_config --cflags)

Likewise for LIBS:

LIBS += $$system(mysql_config --libs)

All of the above goes into your project file (*.pro) of course.

Upvotes: 2

opc0de
opc0de

Reputation: 11768

Mysql is not included in the SQL modules by default so Matt Philip's solution won't work.

What you need to do is install the mysql dev package by doing

sudo apt-get install libmysqlclient-dev

and then add it to the pro file like this

LIB += -L/usr/lib/mysql -lmysqlclient

This worked for me on ubuntu

Upvotes: 0

Matt Phillips
Matt Phillips

Reputation: 9691

To include Qt's SQL modules, you need this

QT += sql

in your .pro file. You also need to make sure the drivers have been compiled, and put into the plugins folder, libqsqlmysql.so in

~/QtSDK/Desktop/Qt/4.8.0/gcc/plugins/sqldrivers

in my case.

Upvotes: 0

Related Questions