I am creating a Qt widget with a backend representation I wrote separately. The backend uses Magick++, and I can get it to compile from the command line:
g++ -c ../SpriteCreator/WriteGIF.cpp sprite.cpp -I ../SpriteCreator/ Magick++-config --cxxflags --cppflags Magick++-config --ldflags --libs -O2
but when I try to compile the project Qt Creator it tells me
/home/tpope/obeyYourThirst/qtSpriteEditor/backend/sprite.cpp:15: error: Magick++.h: No such file or directory
#include < Magick++.h>
I added the path for Magick++.h to the INCLUDEPATH, but now it has an error similar to this:
/home/tpope/obeyYourThirst/qtSpriteEditor/backend/sprite.cpp:66: error: undefined reference to `Magick::InitializeMagick(char const*)'
for every use of a Magick function. It seems to be not including the library. How do I do that in Qt Creator?
Since the .pro files in Qt Creator is (as far as I can tell) used to generate a Makefile, we can use make's ability to run a program on the shell and save its output.
I have added:
QMAKE_CXXFLAGS += $(shell Magick++-config --cppflags --cxxflags)
and
LIBS += $(shell Magick++-config --ldflags --libs)
to my .pro file, and I was able to add:
#include <Magick++.h>
to my program without a compile error, then compile a simple example (Just put out an animated .gif with a couple of colored pixels)
This obviously makes things like cross-compiling a little tricky (I don't know how to reference foreign libraries), but that's a problem for another time.
Related
I'm trying to compile a program i made using SDL2 to work on others computers (or testing VM in this case).
I've been compiling it with what i think are the correct flags, e.g. g++ main.cpp -o main -lSDL2, however when i try executing it on another Ubuntu installation i get this error.
error while loading shared libraries: libSDL2-2.0.so.0: cannot open shared object file: No such file or directory
From my understanding it's not a problem in my compiling but with how i expect it to work on another Linux installation; I've cross-compiled (using mingw32) and tested it (using a freshly installed VM) on Windows adding the correct dlls with the exe (seems to work fine) and I was expecting for it to work in a similar fashion.
What's the standard in this cases? Should i write a setup scripts to install the library dependencies on the target machine? Is there another way I'm not aware of? I've never released an application for Linux (nor Windows) and I'm struggling to find the resources to do things "the right way".
Thanks for everyone suggestions, I ended up settling for the easy way, compiling the "easy to install" libraries dynamically e.g.-lSDL2 and the others statically (checked the licenses and it should be fine) like so:
g++ main.cpp -o main -Wl,-Bdynamic -lSDL2 -lSDL2_image -lSDL2_ttf -Wl,-Bstatic -lSDL2_gfx -static-libgcc -static-libstdc++
I'll put in my documentation how to install the required SDL2 libraries.
I am not sure how familiar you are with pkg-config, but the output for sdl2 is this:
-D_REENTRANT -I/usr/include/SDL2 -lSDL2
This was found from running this:
pkg-config --cflags --libs sdl2
Basically, you need to point to where SDL2 is located BEFORE you actually link to it.
The tool pkg-config is designed to tell you the information you need when you want to link to a package in Linux. You were linking with the library, but you forgot to tell GCC where the library is located.
If you want to compile you code, try this:
g++ main.cpp -o runme `pkg-config --cflags --libs sdl2`
This will automatically grab all of the flags that you need to compile with SDL2 included.
Oh, and you should note, ORDER MATTERS WHEN ADDING FLAGS AND LIBRARIES!!!
There are many questions on SO where the order of compiler options caused all of the problems. Do not be like those people. I suggest you search SO for more info on that.
I'm trying to generate a .exe file with g++ compiler. I tried multiple ways without sucess.
1) QString program = "C:/Strawberry/c/bin/g++";
QStringList arguments;
arguments << "g++ -o dialog C:/Documents/ED30/dialog.cpp";
QProcess process;
process.start(program, arguments);
process.waitForFinished(-1);
2) QProcess::execute("g++ -o dialog2 C:/Documents/ED30/dialog.cpp");
3) QProcess::execute("g++ C:/Documents/ED30/dialog.cpp -o dialog2");
Everytime I have the same error message :
"In file included from C:/Documents/ED30/dialog.cpp:1:0:
C:/Documents/ED30/dialog.h:4:19: fatal error: QDialog: No such file or directory
compilation terminated."
Or sometimes nothing happens.
I'm using Qt 5.7 with MinGW on windows 8.1
EDIT:
So after discussing the issue with members, I did some progress.
Best code until now is :
system("g++ -o dialog2 -I C:/Qt/5.8/mingw53_32/include -I C:/Qt/5.8/mingw53_32/include/QtGui -I C:/Qt/5.8/mingw53_32/include/QtCore -I C:/Qt/5.8/mingw53_32/include/QtWidgets -L C:/Qt/5.8/mingw53_32/lib C:/Documents/ED30/dialog.cpp");
But this indicats me that MinGW isn't a c++ 11 compiler and it suggests me to write "-std=c++11 or -std=gnu++11" in the command-line in order to update the Compiler. After typing it in the compiler, the following error appears: "Unknow command".
I tried with Qt 5.7 and 5.8 without success.
A solution guys ?
It seems the code you are trying to compile dialog.cpp makes use of Qt (QDialog in particular).
When you run g++ -o dialog2 C:/Documents/ED30/dialog.cpp, g++ fails because it cannot find where Qt header and library files are.
The minimal command line to make it work would be:
g++ -o dialog2 -I<PathToQtheaders> -L<PathToQtLibraries> -lQt5Core -lQt5Gui -lQt5Widgets C:/Documents/ED30/dialog.cpp
You might need to add some extra libraries depending on what you code needs. Note that you cannot use Q_OBJECT macro if you just compile it like that (without calling moc etc.).
Tip: Look at the commands generated by qmake on a standard Qt project.
Extra tip: You can use QLibraryInfo::location() to get Qt installation paths.
Also your first example should be:
QString program = "C:/Strawberry/c/bin/g++";
QStringList arguments;
arguments << "-o" << "dialog" << "C:/Documents/ED30/dialog.cpp";
QProcess process = "g++";
process.start(program, arguments);
process.waitForFinished(-1);
I think you are missing the include directory of your Qt headers.
QProcess::execute("g++ -o dialog -I C:\QtDir C:/Documents/ED30/dialog.cpp");
QtDir is the actual location of the Qt Headers on your system like C:\Qt\include
You may also have trouble linking. The whole command is:
QProcess::execute("g++ -o dialog -I C:\QtDir\include -L C:\Qtdir\lib -l Qt C:/Documents/ED30/dialog.cpp")
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.
;-)
I'm trying to import PackageKit into a C++ project I'm working with (as a C++ newbie coming from a mostly Java background). My goal is do some things with the packages I have installed on my system.
I've installed libpackagekit-glib2-16, libpackagekit-glib2-dev, libpackagekit-qt2-6, libpackagekit-qt2-dev, and packagekit (I know I won't need all of these down the line, but I'm just covering my bases for now). I can see that they've been installed here: /usr/include/PackageKit which has the subfolders packagekit-glib2, packagekit-qt2, plugin.
To help me along I'm using qt 5.2.1 to act as a crutch for my Makefiles while I'm still learning, but I'm not actually using any qt resources for now. I've been able to import apt's and dpkg's libraries previously via -lapt-lib and -ldpkg under qt's LIBS+= but I can't figure out how to import the packagekit's library (I've tried multiple variations, but I can't figure out how to properly import this library).
This:
#define I_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE
#include <PackageKit/packagekit-glib2/packagekit.h>
int main(int argc, char *argv[])
{
return 0;
}
Results with this:
g++ -c -std=c++11 -g -Wall -W -D_REENTRANT -fPIE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_CORE_LIB -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -I../console-example -I/usr/include/qt5 -I/usr/include/qt5/QtCore -I. -I. -o main.o ../console-example/main.cpp
In file included from ../console-example/main.cpp:3:0:
/usr/include/PackageKit/packagekit-glib2/packagekit.h:31:41: fatal error: packagekit-glib2/pk-catalog.h: No such file or directory
#include <packagekit-glib2/pk-catalog.h>
If this is necessary, my system is Ubuntu 14.04 64bit and as I've mentioned I'm using qt 5.2.1 to help with the makefile. Thanks to all in advance!
This seems to be a compilation problem. The compiler cannot find packagekit's headers. I suppose that into g++ line you need to add -I/usr/include/PackageKit or something similar.
From within my qt project's .pro file I had to make the following additions to get it to compile and link.
CONFIG += link_pkgconfig # This enables the next line
PKGCONFIG = gtk+-2.0 # This will link against gtk+-2.0
INCLUDEPATH += /usr/include/PackageKit/ \ # This is the include for packagekit
+= /usr/lib/glib-2.0/include/ # This will include glib, which packagekit is dependent on
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.