Adding External libraries to QT 5.1.1 project - c++

I am trying to include the assimp library (http://assimp.sourceforge.net/main_doc.html) for importing assets into my QT project.
I managed to include it in VS2012 but not in QT.
The import wizard gives me this code:
unix|win32: LIBS += -L$$PWD/assimp--3.0.1270-sdk/lib/assimp_debug-dll_win32/ -lassimp
INCLUDEPATH += $$PWD/assimp--3.0.1270-sdk/include
DEPENDPATH += $$PWD/assimp--3.0.1270-sdk/include
win32: PRE_TARGETDEPS += $$PWD/assimp--3.0.1270-sdk/lib/assimp_debug-dll_win32/assimp.lib
else:unix: PRE_TARGETDEPS += $$PWD/assimp--3.0.1270-sdk/lib/assimp_debug-dll_win32/libassimp.a
When i build the code it throws this error
undefined reference to `Assimp::Importer::Importer()'
If i understand it right:
QT / VS2012
INCLUDEPATH =Include directories
LIBS = Library directories
PRE_TARGETDEPS=Additional dependancies
Do i have to manualy add the location off the .dll file into .pro or what am i missing?

Related

CGAL Linking Error QT Creator Project for Windows and Linux

I have problems creating a project using QT with CGAL and Boost on Windows 10.
In this project there are a few .pro Files and all projects without CGAL have compiled. Boost also works without problems. If I compile the CGAL Project i get linking errors:
Link Errors
Here is my .pro file
win32:INCLUDEPATH += C:/CGAL32/include/
win32:INCLUDEPATH += C:/CGAL32/build/include/
win32:INCLUDEPATH += C:/boost_lib_inc/include/
win32:INCLUDEPATH += C:/boost/boost_1_68_0/
win32:CONFIG(release, debug|release): LIBS += -LC:/CGAL32/auxiliary/gmp/lib -lgmp-10 -lmpfr-4 -LC:/CGAL32/build/lib/Release -lCGAL-vc140-mt-4.12.1 -lCGAL_Core-vc140-mt-4.12.1
else:win32:CONFIG(debug, debug|release): LIBS += -LC:/CGAL32/auxiliary/gmp/lib -lgmp-10 -lmpfr-4 -LC:/CGAL32/build/lib/Debug -lCGAL-vc140-mt-gd-4.12.1 -lCGAL_Core-vc140-mt-gd-4.12.1
else:unix:!macx: LIBS += -L$$PWD/../../../../../../usr/lib/x86_64-linux-gnu/ -lCGAL
On Linux all works fine.

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 correctly link your own library to your project in Qt on Windows?

In my QtCreator C++ project I'm using subdirs template and have several subprojects including lib-project. In app-project I'm trying this:
win32:CONFIG(release, debug|release): LIBS += -L../Library/release -lLibrary
else:win32:CONFIG(debug, debug|release): LIBS += -L../Library/debug -lLibrary
else:unix: LIBS += -L../Library -lLibrary
On Linux it works well, but on Windows library compiles (there're .dll and .a files), linker links it (if I change the path to wrong, like -L../Library/debugg I have an error - can't find -lLibrary), but then I have "undefined reference to [my_classes]". INCLUDEPATH and DEPENDPATH are also correct (because it works on Linux):
INCLUDEPATH += $$PWD/.. $$PWD/../Library
DEPENDPATH += $$PWD/.. $$PWD/../Library
Also tried this:
LIBS += -L$$OUT_PWD/../Library/release -lLibrary
Same result, so what should I do?

LNK1104 Error when adding Boost library to Qt project

M'kay so I'm new to Qt and I'm trying to include the boost/filesystem lib to my project. However, when I try to build it, I always get this error:
LNK1104: File "libboost_filesystem-vc140-mt-1_61.lib" cannot be
opened.
Now, I know that this library needs to be build beforehand, so, as described on the Boost-Website I made:
bootstrap
.\b2
and it built just fine. I also used the Qt dialog to add the libary to my project, my .pro-file looks like this:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = ProjectName
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
someclass.cpp \
someclass2.cpp
HEADERS += mainwindow.h \
someclass.h \
someclass2.h
FORMS += mainwindow.ui
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/libarys -llibboost_filesystem-vc140-mt-1_61
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/libarys -llibboost_filesystem-vc140-mt-1_61
else:unix: LIBS += -L$$PWD/libarys -llibboost_filesystem-vc140-mt-1_61
INCLUDEPATH += $$PWD/boost
DEPENDPATH += $$PWD/boost
Apparently, I did something wrong, but I can't figure out, WHAT exactly it is. The internet knows the problem, but it seems there's no "easy" solution to it.
Turned out, my project didn't like the lib-version.
I rebuilt my lib files:
>b2 --build-dir="destination/directory" toolset=msvc --build-type=complete link=static threading=multi --with-filesystem stage
Then, I used the library in
release/link-static/runtime-link-static/threading-multi/
Which is:
libboost_filesystem-vc140-mt-s-1_61
And re-ran qmake for the .pro-file. Then built and executed the application and the error is gone.

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