How can I make QtCreator compile with gsl library? - c++

I am trying to use the GNU Scientific Library (GSL) http://www.gnu.org/software/gsl/ in QtCreator. How can I tell Qt creator to add these flags: http://www.gnu.org/software/gsl/manual/html_node/Linking-programs-with-the-library.html to link correctly?

You need to edit your .pro file and add the extra libs by hand, e.g.:
LIBS += -L/usr/local/lib example.o -lgsl -lgslcblas -lm
See the QMake documentation for more information.

Edit your .pro file and extra libs and include in windows:
`win32{
INCLUDEPATH += C:/gsl-1.11/include/
INCLUDEPATH += C:/gsl-1.11/lib
LIBS += -LC:/gsl-1.11/bin -llibgsl-0 -llibgslcblas-0
}`
then the problem is solved

Related

How can I make OpenCV the default library for my qt projects?

Please suppose that I want to link OpenCV libraries in Qt-creator, in common, I will add headers usingINCLUDEPATH and link libraries using the LIBS variable, which is used in the qmake file but if we use OpenCV in most of our projects then we have to include OpenCV library every time, so is there any way to add opencv libraries automatically at the time of creating a project.
I use the below command to add OpenCV libraries for my projects every time.
INCLUDEPATH += -I/usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_stitching -lopencv_superres ...and etc.
UPDATE
I will use the following headers for OpenCV4:
INCLUDEPATH += /usr/local/include/opencv4
1) You can create a .prf (project feature) file in your mkspecs/features directory:
/usr/share/qt5/mkspecs/features/opencv.prf
INCLUDEPATH += -I/usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_stitching -lopencv_superres ...and another libraries
Now simply add CONFIG += opencv to your .pro file to have it working. Or you can even auto-enable this feature by editing mkspecs/qconfig.pri:
/usr/share/qt5/mkspecs/qconfig.pri
...
CONFIG += ... opencv
...
BTW. qconfig.pri is a part of qt_config, which is loaded by all QMake's machine-dependent specs, so it should always work. However, it's also possible to patch only a specific spec (for example, /usr/share/qt5/mkspecs/linux-g++/qmake.conf, or whatever is appropriate for your configuration). Of course, it's even possible to add all these INCLUDEPATH+=... and LIBS+=... straight into that qmake.conf and get rid of the .prf file completely.
2) Alternatively, if you don't want to pollute Qt installation, you can use manual include:
opencv.pri
INCLUDEPATH += -I/usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_stitching -lopencv_superres ...and another libraries
myprogram.pro
include(path/to/opencv.pri)
...
When you installed opencv you must also install the opencv.pc file, this file can be used to make it simple, since Qt supports package.config, if so, it replaces what it shows by the following:
unix: CONFIG += link_pkgconfig
unix: PKGCONFIG += opencv
Actually Qt Creator offers a simple way, you just have to right click on the name of your project and select the option Add Library:
Then you will get a dialog where you must select the type of library:
In this case I used the fourth option, and put the name of the library: opencv.
Then you press the next and finish buttons.

How to avoid automatic adding of /usr/lib64 in Qt pro file

I have a Qt project. I can add some libraries using the commands like:
LIBS += -lopencv_core
They work perfectly for me. However, if I check the output, I have there other libraries, too. For example /usr/lib64, without mentioning this anywhere in the project. How can I avoid that addition?
You can explicity remove these paths. For example, I use that to remove all standard path (lib and includes) :
unix {
LIBS -= -L/usr/lib/
LIBS -= -L/usr/lib64/
LIBS -= -L/usr/lib
LIBS -= -L/usr/lib64
INCLUDEPATH -= /usr/include/
INCLUDEPATH -= /usr/include
}

Ubuntu Qt link boost log

I try to link the boost 1.55 log library with a Qt *.pro file.
INCLUDEPATH += $$system(echo ${BOOST_INCLUDE_DIR})
LIBS += -L$$system(echo ${BOOST_LIB_DIR})
LIBS += -lboost_system -lboost_filesystem -lboost_thread -lboost_log
I get a reference error with boost log , because I didn't define
-DBOOST_LOG_DYN_LINK
Can anyone tell me how to define this inside the *.pro file?
In my CMake file i can use: ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK)
What is the corresponding command in qmake?
Use DEFINES:
DEFINES += BOOST_LOG_DYN_LINK

OpenGL Ubuntu 13.10 QtCreator - undefined reference to `glutMainLoop`

If I try to execute the code from here, the OpenGLBook, I get this error messages:
undefined reference to glutMainLoop
undefined reference to glGetString
undefined reference to glClearColor
and so on ... I installed the following packages:
libglew-dev, liblglew1.8, freeglut3-dev and freeglut3.
I am running on Ubuntu 13.10 with Qt Creator v3.0.0.
My .pro file looks like this:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
Build step for debugging is qmake Project.pro -r -spec linux-g++ CONFIG += debug
How can I fix my project?
Had to change my pro file to
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
# this is the important part
unix|win32: LIBS += -lGLU
unix|win32: LIBS += -lGL
unix|win32: LIBS += -lglut
Welcome to c++ !
You are using a library (freeglut I gather) and for this you need 2 things :
1) include the headers (*.h file(s)) that declare the functions/classes/methods that you need
2) your program needs to link with the actual shared library (.so files in Linux)
In your .pro file you need to specify the path to the libraries you want to link with. Add this :
LIBS += -lglut
It means add the library glut to the list of libraries to link.

How do you include CGAL into a QT project in QT Creator?

I am trying to run some of the sample example code from CGAL as a Qt project, to run in Qt Creator. I expect that I will have to modify the .pro file. How should it be modified to use CGAL libraries?
I'm not familiar with CGAL specifically, but in general, you would need to add the following to your .pro file:
INCLUDEPATH += /path/to/cgal/headers
LIBS += -Lpath/to/cgal/libraries -lcgal_dll_name
You may also need to add some DEFINES if CGAL requires it, i.e.
DEFINES += SOME_MACRO_THAT_CGAL_REQUIRES
If you were looking for help on CGAL specifically, please clarify your question and I will delete this answer.
Although this is an old question, just for the sake of having a more complete answer, this is what I had to do in the .pro file:
INCLUDEPATH += /usr/include/
LIBS += -L/usr/include/
LIBS += -lCGAL
LIBS += -lgmp
LIBS += -lmpfr // not really needed for me, but added since gmp had to be added too
QMAKE_CXXFLAGS += -frounding-math -O3
Do NOT add stuff like the following, it will get you into trouble with weird error messages, as discussed in this link.
INCLUDEPATH += /usr/include/CGAL # do NOT add this!
LIBS += -L/usr/include/CGAL # do NOT add this!
I'm using Qt 4.8.6, gcc and Fedora 24, and here is my .pro for Qt-CGAL projects :
#-------------------------------------------------
#
# Project created by QtCreator 2017-01-08T14:50:29
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = My CGAL_test
TEMPLATE = app
LIBS += -lgmp -lmpfr -lCGAL
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui