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

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
}

Related

How to add an hdf5 to a Qt-Project?

Situation:
I need to add a library (HDF5 in my case) to my qt project.
I know how to code c++ enough for my purposes, but i have no clue about the .pro file. When i try to google my problem or general guides for adding libraries i find lots of answers but understand none of them, because they require more knowledge then i have. They say stuff like "compile it here and there", "add this and that to your system", "use qmake in directory xyz". Can someone please answer the question so that one who only knows a bit of c++ and the green compile & run button of qt understands it? Would be great :-)
What I tired:
I know that there is a wizarb in qt that can add librarys to projects. I used it to add the libraries needed. I added them as "external librarys".
I tried as dynamic or static, i tried adding only the hdf5.lib or the hdf5_cpp.lib too.
Problem:
When I do it as I described above and try to use a function from the added library i always get errors like: undefined reference to H5::Function_Name_xyz.
My .pro looks like (generated by the qt add-library-wizard):
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
main.cpp
#Add external static library "hdf5.lib":
unix|win32: LIBS += -L'C:/Program Files/HDF_Group/HDF5/1.10.2/lib/' -lhdf5
INCLUDEPATH += 'C:/Program Files/HDF_Group/HDF5/1.10.2/include'
DEPENDPATH += 'C:/Program Files/HDF_Group/HDF5/1.10.2/include'
win32:!win32-g++: PRE_TARGETDEPS += 'C:/Program Files/HDF_Grou/HDF5/1.10.2/lib/hdf5.lib'
#Add external static library "hdf5_cpp.lib"
unix|win32: LIBS += -L'C:/Program Files/HDF_Group/HDF5/1.10.2/lib/' -lhdf5_cpp
INCLUDEPATH += 'C:/Program Files/HDF_Group/HDF5/1.10.2/include'
DEPENDPATH += 'C:/Program Files/HDF_Group/HDF5/1.10.2/include'
win32:!win32-g++: PRE_TARGETDEPS += 'C:/Program Files/HDF_Group/HDF5/1.10.2/lib/hdf5_cpp.lib'
Using:
C++
Qt 5.10.1
MinGW 32bit
HDF5 1.10.2
Windows 7
I had this same issue awhile back. I did the following to correct the linking error.
Make sure you run qmake (Build-> Run qmake) after adding a new library to the .pro file.
Since you are using windows with the pre-built HDF library, you should use the MSVC2015 32 bit Build&Run kit. The pre-built libraries used Microsoft Visual C++ compiler, so to use the HDF libraries you will need to use that compiler.
Per the HDF documentation, you need to list the external libraries first. The following snippit shows my setup using dynamic libraries.
If your using dynamic libraries be sure to add DEFINES += H5_BUILT_AS_DYNAMIC_LIB to your .pro file.
win32: LIBS += -L$$PWD/'../../../../../Program Files/HDF_Group/HDF5/1.10.4/lib/' -lszip -lzlib -lhdf5 -lhdf5_cpp
INCLUDEPATH += $$PWD/'../../../../../Program Files/HDF_Group/HDF5/1.10.4/include'
DEPENDPATH += $$PWD/'../../../../../Program Files/HDF_Group/HDF5/1.10.4/include'

How to link to SDL2 libraries under Qt Creator

I have compiled the latest SDL2 libraries, obtained from the 'official' mercurial repository, and followed the instructions for the Ubuntu/Linux build.
But Qt creator fails to link the statically built libraries. Here's the qmake script:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
unix:!macx: LIBS += -L/usr/local/lib/libSDL2.a
INCLUDEPATH += /usr/local/include
SOURCES += main.cpp
The linker reports several undefined references, including SDL_Init.
You have to change your LIBS line to this:
LIBS += -L/usr/local/lib -lSDL2
as -L let you define the path where linker looks for libraries to link, while -l defines which library to link to. On Unix systems the library called ASD is represented by a libASD.so file (in this example .so is for shared library, in your case there is .a as it is static library).
EDIT:
I've prepared very simple main.cpp:
#include <SDL/SDL.h>
int main()
{
SDL_Init(SDL_INIT_VIDEO);
return 0;
}
build SDL 2.0.3 as static library with /usr/local prefix and I needed to add 2 other libraries to my .pro file to compile this. Here it is:
TEMPLATE = app
CONFIG += console
CONFIG -= qt
CONFIG -= app_bundle
SOURCES += main.cpp
LIBS += -L/usr/local/lib -lSDL2 -ldl -lpthread
INCLUDES += /usr/local/include
And now it compiles flawlessly.

Qt program fails to run with errors referencing libwinpthread-1

I've made a C++/OpenGL application using the Qt framework, but I cannot to run *.exe file. I always get errors with libwinpthread-1.
I already read articles about that, but all dll's are in the Qt folder, so I don't understand what the problem is. Please take a look at my *.pro file:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp \
sliceobj.cpp
unix|win32: LIBS += -lOPENGL32
unix|win32: LIBS += -L$$PWD/../../../../5.0.2/mingw47_32/lib/ -lglut32
QMAKE_LFLAGS += -static-libgcc -static-libstdc++
QMAKE_CXXFLAGS_WARN_ON += -Wno-unknown-pragmas
INCLUDEPATH += $$PWD/../../../../5.0.2/mingw47_32/include
win32 {
message("* Using settings for windows")
INCLUDEPATH += "C:\\opencv\\build\\include" \
"C:\\opencv\\build\\include\\opencv" \
"C:\\opencv\\build\\include\\opencv2"
LIBS += -L"C:\\opencv\\build\\x86\\vc11\\bin" \
-lopencv_core247\
-lopencv_highgui247\
-lopencv_imgproc247\
-lopencv_video247\
LIBS += -L"C:\\opencv\\build\\x86\\vc11\\staticlib" \
-lopencv_core247\
-lopencv_highgui247\
-lopencv_imgproc247\
-lopencv_video247\
}
Use Dependency Walker to see what exactly your code links against + Which libraries are loaded in runtime. Open your executable with DW and you will see DLL's that are linked against. They need to be present in PATH or beside your executable. Press F7 to start profiling to see which libraries are loaded in runtime. Here as snapshot:
Ok, i know that's not good, but i'm just added this files into debug directory .

How to add external libraries to qt4 application c++

what is the best way to add additional compiled libraries to my qt project ?
For example boost or poco libs ?
Thanks :)
If you're using the GCC compiler add something like this to the .pro file:
For Boost:
INCLUDEPATH += d:/Biblioteki/C++/boost/boost_1_44_0a
LIBPATH += d:/Biblioteki/C++/boost/boost_1_44_0a/stage/lib
LIBS += -lboost_system-mgw44-mt-d-1_44
LIBS += -lboost_filesystem-mgw44-mt-d-1_44
LIBS += -lboost_date_time-mgw44-mt-d-1_44
For Poco:
INCLUDEPATH += d:/Biblioteki/C++/Poco/poco-1.3.6p2-mingw-qt2/include
LIBPATH += d:/Biblioteki/C++/Poco/poco-1.3.6p2-mingw-qt2/lib
LIBS += -lPocoFoundationd
LIBS += -lPocoNetd
LIBS += -lPocoUtild
LIBS += -lPocoXML
INCLUDEPATH - is the location of directory with header files
LIBPATH - is the location of directory with *.a files
LIBS - contains list of libraries you want to use in your application

How can I make QtCreator compile with gsl library?

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