Adding compilation flags to Qt to use mysql - c++

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?

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.

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.

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

Related

ft2build.h: No such file or directory - Freetype 2.6

I am trying to build from Linux cause I decided to start using Jenkins, my personal work but, even with freetype installed: v.2.6.3, it doens't recognize this ft2build.h.
This is the QT Pro with freetype loaded. I'm now running on UBuntu 16.04:
linux {
message("Build for Linux")
DEFINES += LINUX
DEFINES += BOOST_LOG_DYN_LINK
LIBS += -lGLU
LIBS += -lfreetype
LIBS += -L/usr/lib/x86_64-linux-gnu/-libboost_timer.so -libboost_log.so -libboost_log_setup.so -libboost_system.so -libboost_thread.so -libboost_filesystem.so
}
So i tried to change also the lib pointer doing manually as:
LIBS *= -L/usr/local/lib/ -lfreetype
but still nothing going properly. The error I get is from lGLU
In file included from displays/display.cpp:3:0:
displays/./../oglft/oglft.h:50:22: fatal error: ft2build.h: No such file or directory
compilation terminated.
Makefile:1093: recipe for target 'display.o' failed
I do always run 'qmake make clean' then /usr/lib/x86_64-linux-gnu/qt5/bin/qmake && make && make check to be sure it starts properly. Can someone help me solving the bug?
I've checked where freetype lib is located by doing:
pkg-config --cflags --libs freetype2
and this is what I get
-I/usr/local/include/freetype2 -L/usr/local/lib -lfreetype
PROBLEM SOLVED!
I have had to set FREETYPE in the environment variables as BOOST too and everything is now working properly!
Here is how is mine:
export BOOST=/var/lib/jenkins/workspace/boost_1_59_0
export FREETYPE=/var/lib/jenkins/workspace/freetype-2.6.3
I preferred to move those two libs under Jenkins to avoid permissions problems.
;-)

Adding Google's protocol Buffer to Qt ; Disable Compiler Warnings

In order to add the protobuf library from google to my Qt Project I did the following steps. I use Windows 10 and Qt 5.6 with the mingw32compiler.
1 Install protobuf
Therefore I installed MSYS with mingw and cd to the protobuf-3.0.0-beta-2 directory where I ran the configure script ./configure --prefix= 'cd /c/qt/Tools/mingw492_32/ ; pwd -W making sure to install protobuf in the Qt compiler directory. Afterwards I ran makeand make install.
2 Compile Project with protobuf
Now I add the include path INCLUDEPATH += C:/qt/tools/mingw492_32/includeand the library path LIBS += $$PWD/../protobuf-3.0.0-beta-2/src/libs/libprotobuf.a to my Qt project files to make the google protobuf available.
Compiling my project works but I receive a lot of warnings since the protobuf library has a lot of unused parameters / dummy functions. Is there any way to turn of the warnings obtained from the external protobuf library?
You need to tell the compiler that the protobuf headers are system headers. The -I flag tells the compiler where to look for non-system headers, whereas -isystem gives directories containing system headers. System headers do not produce warnings. But INCLUDEPATH uses -I.
Instead of:
INCLUDEPATH += C:/qt/tools/mingw492_32/include
Try:
QMAKE_CXXFLAGS += -isystem C:/qt/tools/mingw492_32/include

Failed to link openssl to Qt

I have started a project with Qtcreator on linux. This project uses the Openssl library to work.
So In my .pro file I have added theses lines :
LIBS += -lssl
LIBS += -lcrypto
So on linux it works perfectly.
But, I have to continue my project on windows. I had to install Openssl with cygwin, I have chosen this package : "cygwin32-openssl-1.0.1e-1.tar.bz2" because I compile in 32bits.
I have created a sub-repertory, named libs, in my program folder and I put the three openssl folders (bin, include and lib) in my "libs" repertory.
The content of the lib directory is :
libcrypto.a
libcrypto.dll.a
libssl.a
libssl.dll.a
pkgconfig/libcrypto.pc
pkgconfig/libssl.pc
pkgconfig/openssl.pc
In the bin directory I have 2 .dll, cygcrypto-1.0.0.dll and cygssl-1.0.0.dll
I added in my .pro file these lines :
LIBS += -lssl
LIBS += -lcrypto
LIBS += -L"$$PWD/libs/openssl/lib/"
INCLUDEPATH += $$PWD/libs/openssl/include/
If I change -L"$$PWD/libs/openssl/lib/" by -L"$$PWD/libs/openssl/bin/", the compilator don't recognized the -lssl and -lcrypto options.
QtCreator recognized the headers files (for example ) and when I compile, no error occurred.
But when I launch my program, it doesn't work and no error appears.
So I put a breaking point at the begining of my main function, and I re-launch the program. After that a little window indicates to me this error :
Executable failed: During startup program exited with code 0xc0000135
I use Qt 5.4.0 and Mingw 32bits
I don't undertsand why it doesn't work. Can you help me please ?
Thank you.
The entirety of your project needs to use cygwin, or none of it. Since I assume you're compiling using a Visual Studio compiler, you'll need to use an OpenSSL build that isn't cygwin-dependent. For example, the one from Shining Light Productions, the de-fact OpenSSL binary purveyor for Windows.

QMake not finding GraphicsMagick libraries

I am trying to link a Qt program with GraphicsMagick, but Qt/qmake refuses to search /usr/local/* for GraphicsMagick++-config. I am using the $$system() command to fetch the flags like so:
QMAKE_CXXFLAGS += $$system(GraphicsMagick++-config --cppflags --cxxflags)
QMAKE_LIBS += $$system(GraphicsMagick++-config --ldflags --libs)
But every time, qmake complains /bin/sh: GraphicsMagick++-config: command not found. I have tested my path, and I can see /usr/local/bin from sh, csh, zsh, and bash. I am not sure why Qt can't find this command. Is there something simple I am missing?
I am running OS X 10.9, with Qt 5.3.1.
Make sure that you run qmake from the same shell where you did the PATH test, running it through a Finder-launched QtCreator might not inherit the environment if you set it in your ~.*shrc file.
I tried your code and qmake properly calls GraphicsMagick++-config with my brew installed GraphicsMagick.
FWIW, even though you might get the same error, a better way to get it to work would be to let qmake figure out the pkgconfig logic itself:
CONFIG += link_pkgconfig
PKGCONFIG = GraphicsMagick++

Linking freeglut with Qt Creator in Linux

I currently run Arch Linux on my laptop and was hoping to know why Qt Creator isn't finding my glut library (which exists on my system).
My setup qmake file looks as follows:
...
/*sources and headers above*/
QT += opengl
LIBS += -lfreeglut
INCLUDEPATH += -L/usr/lib/
And when I run a locate glut, I get the following:
/usr/include/kwinglutils.h
/usr/include/kwinglutils_funcs.h
/usr/include/GL/freeglut.h
/usr/include/GL/freeglut_ext.h
/usr/include/GL/freeglut_std.h
/usr/include/GL/glut.h
/usr/lib/libglut.a
/usr/lib/libglut.so
/usr/lib/libglut.so.3
/usr/lib/libglut.so.3.9.0
/usr/share/avogadro/fragments/amino_acids/D-glutamic_acid.cml
/usr/share/avogadro/fragments/amino_acids/D-glutamine.cml
/usr/share/avogadro/fragments/amino_acids/L-glutamic_acid.cml
/usr/share/avogadro/fragments/amino_acids/L-glutamine.cml
/usr/share/licenses/freeglut
/usr/share/licenses/freeglut/LICENSE
/var/lib/pacman/local/freeglut-2.6.0-1
/var/lib/pacman/local/freeglut-2.6.0-1/changelog
/var/lib/pacman/local/freeglut-2.6.0-1/desc
/var/lib/pacman/local/freeglut-2.6.0-1/files
Note that I have tried -lglut32 in my qmake file as well.
What could I be missing here?
When you specify -lfoobar in your .pro file (or with gcc in general), you're directing the compiler to search for the library libfoobar.a. Judging from your locate output it looks like you want:
LIBS += -lglut
Oh, silly me. I just realized that the correct lib to add was just -lglut and not -lglut32. This is because there exists libglut.so, and not libglut32.so.