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 .
Related
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'
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
}
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.
When I include something in Qt Creator, later I find out that that include does not exist, I want to correct that mistake by using a right path, or just deleting the include. But, that did not work, even if I delete the wrong include, but Qt Creator still try to find that include in the next build/run. I have already try to rebuild/clean the project but that does not work either. The only solution was to create a new project, or place the included file in that "wrong" place. I thought this question should not be a difficult one. But I fail to solve it.
for example, this is my pro. file.
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = simpleStitch
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += C:\opencv249\build\includes
LIBS += C:\opencv249\build\x64\vc12\lib\opencv_core249.lib
LIBS += C:\opencv249\build\x64\vc12\lib\opencv_highgui249.lib
LIBS += C:\opencv249\build\x64\vc12\lib\opencv_features2d249.lib
LIBS += C:\opencv249\build\x64\vc12\lib\opencv_imgproc249.lib
LIBS += C:\opencv249\build\x64\vc12\lib\opencv_stitcher249.lib
LIBS += C:\opencv249\build\x64\vc12\lib\opencv_calib3d249.lib
LIBS += C:\opencv249\build\x64\vc12\lib\opencv_nonfree249.lib
I have make a mistake in the LIBS += C:\opencv249\build\x64\vc12\lib\opencv_stitcher249.lib.
the right one should be stitching249.lib.
after I correct it to be stitching249.lib. the qt still try to find the C:\opencv249\build\x64\vc12\lib\opencv_stitcher249.lib. it is pretty strange. qt does not recognize my change in the pro. file even if I use the clean/ rebuild.
Run qmake? if you make changes to the .pro file then you need to qmake again or it will just be building against whatever is there from your last qmake
Please give more information, so that we can understand specific problem. Here is what you need to do before starting a new project.
To add kits, select Tools > Options > Build & Run > Kits > Add.
Each kit consists of a set of values that define one environment, such as a device, compiler, and Qt version. If you know you have installed a Qt version, but it is not listed in Tools > Options > Build & Run > Qt Versions, you must add it.
Also check that your compiler is listed in Tools > Options > Build & Run > Compilers.
And also you should modify your .pro file in order to your settings. Here is one of my project's .pro file. You can modified it yourself...
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = myTarget
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib \
-lopencv_core \
-lopencv_imgproc \
-lopencv_highgui \
-lopencv_ml \
-lopencv_video \
-lopencv_features2d \
-lopencv_calib3d \
-lopencv_objdetect \
-lopencv_contrib \
-lopencv_legacy \
-lopencv_flann
Then, in your code you need to include which libraries you want to use.. Such as:
#include <QMainWindow>
#include <opencv/cv.h>
#include <opencv/highgui.h>
I have never used Windows. As I know in windows symbol \ occurs problem if you not use 2 of them. Here is an example to understand clearly..
INCLUDEPATH += D:\\ProgrammingTools\\opencv\\build\\include
CONFIG( debug, debug|release ) {
LIBS += -LD:\\ProgrammingTools\\opencv\\build\\x86\\vc10\\lib\
-lopencv_core246d\
-lopencv_highgui246d\
-lopencv_imgproc246d\
-lopencv_features2d246d\
}
else {
LIBS += -LD:\\ProgrammingTools\\opencv\\build\\x86\\vc10\\lib\
-lopencv_core246\
-lopencv_highgui246\
-lopencv_imgproc246\
-lopencv_features2d246\
}
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.