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

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

Related

wxWidgets autoconf setup doesn't set include dirs as -Isystem but as -I

I have inherited a build system that uses autoconf and automake to build. I am not at all familiar with how this works except on a high level.
The build system itself works fine. However a lot of warnings are generated from system headers. In my case wxWidgets. The cause of this is that the include dir of wxWidgets is passed as -I instead of -isystem. I have searched online but I can't find how I can change this.
The following code is in the configure.ac file:
AM_OPTIONS_WXCONFIG
AM_PATH_WXCONFIG(3.0.2, wxWin=1, , ,[--debug=yes])
if test "$wxWin" != 1; then
AC_MSG_ERROR([
wxWidgets must be installed on your system
but no wx-config script could be found.
Please check that wx-config is in path, the directory
where wxWidgets libraries are installed as returned by
'wx-config --libs' is in the linker path (LD_LIBRARY_PATH
or equivalent variable) and wxWidgets version is 2.9.4 or
above.
])
fi
if test "$wxWin" != 0; then
AC_DEFINE(HAVE_WXWIDGETS,1,[define if the wxWidgets 3.0.2. or higher is available])
fi
Then there is a Makefile.am which does the following:
bin_PROGRAMS = project
project_SOURCES = {sources here}
project_CPPFLAGS = $(AM_CPPFLAGS) $(PROJECT_CPPFLAGS) $(WX_CPPFLAGS)
project_CFLAGS = $(AM_CFLAGS) $(PROJECT_CFLAGS) $(WX_CFLAGS)
project_CXXFLAGS = $(AM_CXXFLAGS) $(PROJECT_CXXFLAGS) $(WX_CXXFLAGS)
project_LDFLAGS = $(AM_LDFLAGS)
project_LDADD = $(AM_LIBADD) $(WX_LIBS)
There doesn't seem an option that I can specify it as a system header in some way.
Do anyone of you know how I can tackle this?
The problem has nothing to do with autoconf. It's the wx-config tool that is the culprit. That tool is used to obtain the include directories. For instance invoking wx-config --cxxflag will result in this:
-I/usr/lib/wx/include/gtk2-unicode-3.1 -I/usr/include/wx-3.1 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXGTK__ -pthread
Which is passed to the compiler. There are a couple of ways of solving this. Either manually replace it in the output or patch wx-config.

Adding a library to a makefile

I just installed RtMidi for a project and compiled it. The examples in the tests folder work and so does my code if I put it in the folder and include it in the Makefile that compiles all the examples. How can I use RtMidi in a project with #include <RtMidi.h> instead of having my code in the tests folder? More specifically, what should I put in my Makefile? I've read a bit about dynamic and static libraries but I have no idea what I should be looking for. I've tried adding -llibrtmidi and /usr/local/lib/librtmidi.a without success.
In a standard Makefile, the CXXFLAGS macro defines flags for the C++ compiler. You will need to add -I<path to header directory> to this macro for the compiler to find the RtMidi header files.
Then you will need to add -L<path to lib directory> to the link step of the Makefile so that -lrtmidi will find the library file. (Note that you omit the lib prefix for the -l command)
Based on your description of your environment, you may require something like
CPPFLAGS += -I/usr/local/include
LDFLAGS += -L/usr/local/lib
LDLIBS += -lrtmidi
in your Makefile. make uses a lot of these implicit variables.

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.

Sha512 hash in QT via OpenSSL

I'm trying to use the Sha512 function in openSSL but can't seem to get it to work as I get compiler errors just starting into the code. I include #include <openssl/sha.h> at the top of the .cpp file, then in the action of a button event I put just the following code below.
SHA512_CTX ctx;
SHA512_Init(&ctx);
//Will uncomment below in later if I get SHA512_Init to work
//SHA512_Update(&ctx, string, strlen(string));
//SHA512_Final(digest, &ctx);
I get a linker error telling my undefined symbols for architecture x86_64, implying the function does not exist?
I'm aware QT 5 has a hash function, but I'm limited to QT 4.8 so I can not use the cryptographic sha512 hash function available in the QT 5+ framework.
Any help is appreciated!
Used macports to install openssl
I'm using Mac OS 10.9.2
MAKE FILE
#-------------------------------------------------
#
# Project created by QtCreator 2014-06-11T20:27:49
#
#-------------------------------------------------
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = ExchangeTab
TEMPLATE = app
LIBS += -L/usr/include/openssl -openssl
INCLUDEPATH += /usr/include/openssl
SOURCES += main.cpp\
mainwindow.cpp \
httpsocket.cpp \
cloaksend.cpp \
exchange.cpp
HEADERS += mainwindow.h \
httpsocket.h \
cloaksend.h \
exchange.h
FORMS += mainwindow.ui
RESOURCES += \
AppResources.qrc
Looking for cross platform solution please.
You need to link to the right library (openSSL)
Have a look here: How to Include OpenSSL in a Qt project
Specifically, add this to your .pro file.:
LIBS += -L/opt/local/lib/ -lcrypto
For including .h files add this line to your .pro file :
INCLUDEPATH += /opt/local/include
[1] says that the default include path will be /opt/local/include/.
LIBS += -L/usr/include/openssl -openssl
INCLUDEPATH += /usr/include/openssl
This looks incorrect. The OpenSSL libraries are libcrypto (-lcrypto) and libssl (-lssl). There is nolibopenssl(-lopenssl). Try:
LIBS += -L/usr/lib -lcrypto
INCLUDEPATH += /usr/include/openssl
But the libraries are version 0.9.8. You might consider upgrading to 1.0.1h.
$ ls /usr/lib | grep crypto
libcrypto.0.9.7.dylib
libcrypto.0.9.8.dylib
libcrypto.dylib
libk5crypto.dylib
And
$ /usr/bin/openssl version
OpenSSL 0.9.8y 5 Feb 2013
If you choose to upgrade, OpenSSL will install into /usr/local/ssl. Avoid mixing/matching version of OpenSSL with the following.
INCLUDEPATH += /usr/local/ssl/include/openssl
LIBS += /usr/local/ssl/lib/libcrypto.a
Its OK to specify objects and archives in LIBS. See How to add object files to a project in Qt.
Okay so I may have answered my own question but I will need some help understanding why it worked.
My make file was indeed the problem. I added the following 3 lines.
INCLUDEPATH += $$OPENSSL_INCLUDE_PATH
LIBS += $$join(OPENSSL_LIB_PATH,,-L,)
LIBS += -lcrypto
Then it magically compiled just fine. I found these in another project made with QT that compiled for OpenSSL.
Interestingly enough. I removed the top two lines so only the following remained. Then ran the clean on my project to be sure the code was being recompiled.
LIBS += -lcrypto
This also just 'worked' without linker errors. It looks like that is the only command I need. Question is... will that be cross platform friendly if I take this code and compile on linux or windows? That I am not sure, but this worked.

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?
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