Linking QtCreator && OpenCv - c++

I'm having a problem linking a library from opencv(2.3.1) and can't find a way to resolve it..
I'm using qtCreator with mingw and the pre-built vc10 dynamic lib files.
So, here is what I have done till now:
.pro file:
TEMPLATE = app
INCLUDEPATH += "E:/opencv/build/include/"
INCLUDEPATH += "E:/opencv/build/include/opencv/"
INCLUDEPATH += "E:/opencv/build/include/opencv2/"
INCLUDEPATH += $$PWD/../opencv/build/x86/vc10
DEPENDPATH += $$PWD/../opencv/build/x86/vc10
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../opencv/build/x86/vc10/lib/ -lopencv_core231
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../opencv/build/x86/vc10/lib/ -lopencv_core231d
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../opencv/build/x86/vc10/lib/ -lopencv_highgui231
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../opencv/build/x86/vc10/lib/ -lopencv_highgui231d
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../opencv/build/x86/vc10/lib/ -lopencv_imgproc231
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../opencv/build/x86/vc10/lib/ -lopencv_imgproc231d
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../opencv/build/x86/vc10/lib/ -lopencv_calib3d231
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../opencv/build/x86/vc10/lib/ -lopencv_calib3d231d
...
I have tested an application that used highgui libs from opencv and it compiled and worked nicely, but when I try to use cvPyrDown(from imgproc_c.h) it compiles but can't load the library correctly it "exits unexpectedly" with code -1073741515.
I don't understand why that is.. as you can see from the .pro file I linked the imgproc libs just like the highgui, but it still won't work!
Any suggestions ?
Edit
Ok, the problem is that visual studio creates libraries with different naming conventions than g++ and that's why it won't work.. If this is true, I still can't explain why it works with the highgui libs.. Any ideas ?

Shouldn't you be using the MSVC version of Qt then?

Which version of Opencv is this? I suggest trying latest 2.3, and using CMake instead of .pro files, which is the build system for the overall project.
Then you just file->open-project on the CMakeLists.txt, and you can just look at how examples are set up with CMake.
If this is latest, then 1) highgui uses QT so it makes sense that it might play nicer with qt creator and 2) building with .pro on windows might be untested; a unavoidable need for CMake would not be surprising.
Edit: Look at the CMakeLists.txt files for the libraries ....
# CMakeLists.txt for /modules/highgui
#YV
if (HAVE_QT)
if (HAVE_QT_OPENGL)
set(QT_USE_QTOPENGL TRUE)
endif()
INCLUDE(${QT_USE_FILE})
SET(_RCCS_FILES src/window_QT.qrc)
QT4_ADD_RESOURCES(_RCC_OUTFILES ${_RCCS_FILES})
SET(_MOC_HEADERS src/window_QT.h )
QT4_WRAP_CPP(_MOC_OUTFILES ${_MOC_HEADERS})
set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} ${QT_LIBRARIES} ${QT_QTTEST_LIBRARY})
set(highgui_srcs ${highgui_srcs} src/window_QT.cpp ${_MOC_OUTFILES} ${_RCC_OUTFILES} )
endif()
if(WIN32)
if(NOT HAVE_QT)
set(highgui_srcs ${highgui_srcs} src/window_w32.cpp)
endif()
set(highgui_srcs ${highgui_srcs} src/cap_vfw.cpp src/cap_cmu.cpp src/cap_dshow.cpp)
if(HAVE_MIL)
set(highgui_srcs ${highgui_srcs} src/cap_mil.cpp)
endif()
endif()
if(UNIX)
if(NOT HAVE_QT)
if(HAVE_GTK)
set(highgui_srcs ${highgui_srcs} src/window_gtk.cpp)
endif()
endif()
....
endif()
But "imgproc"'s CMakeLists.txt doesn't do any specific checks ... just passes the buck to main opencv lib:
define_opencv_module(imgproc opencv_core)

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.

Linking a lib file with a non-standard name in Qt

On Windows, I'm attempting to add an external DLL to my Qt project (via Qt Creator). I have the following generated artifacts I'm trying to reference:
target/debug/mylib.d
target/debug/mylib.dll
target/debug/mylib.dll.d
target/debug/mylib.dll.lib
Adding the library/dll generates the following entry in my .pro file:
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/target/release/ -lmylib.dll
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/target/debug/ -lmylib.dll
INCLUDEPATH += $$PWD/target/debug
DEPENDPATH += $$PWD/target/debug
Qt is expecting "mylib.dll.lib" to be named "mylib.lib", so with the above configuration the build fails with the error:
error: LNK1104: cannot open file 'mylib.lib'
The build works correctly if I rename "mylib.dll.lib" to "mylib.lib", but I'd rather not introduce this extra step, if possible. The dll.lib suffix is generated by Rust/Cargo, and there aren't any plans to allow this to be configured.
After doing some research, I've tried a couple of different options, including referencing it in PRE_TARGETDEPS, but I can't make the LNK1104 error disappear. What am I missing?
I figured it out. The trick is to refer to the files directly (i.e. not using the -L / -l parameters), like this:
win32:CONFIG(release, debug|release): LIBS += $$PWD/target/release/mylib.dll.lib
else:win32:CONFIG(debug, debug|release): LIBS += $$PWD/target/debug/mylib.dll.lib
win32:CONFIG(release, debug|release): LIBS += $$PWD/target/release/mylib.dll
else:win32:CONFIG(debug, debug|release): LIBS += $$PWD/target/debug/mylib.dll

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?

Adding jsoncpp external library to my qt project : (symbol(s) not found for architecture x86_64)

I'm trying to add jasoncpp library to my C++ qt project.
I included the header, and linked (I think) the library but I get these errors:
"symbol(s) not found for architecture x86_64" and "linker command failed with exit code 1 (use -v to see invocation)".
The symbols not found are obviously the ones concerning jsoncpp library.
This is my makefile:
QT += core gui webkitwidgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = JsonTest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/lib/release/ -ljson
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/lib/debug/ -ljson
else:unix: LIBS += -L$$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/lib/ -ljson
INCLUDEPATH += $$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/include
DEPENDPATH += $$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/include
I really don't know how to proceed so thanks in advance.
If you installed it using cmake, try this commands:
mkdir -p build/debug
cd build/debug
cmake -DCMAKE_BUILD_TYPE=debug -DJSONCPP_LIB_BUILD_STATIC=ON -DJSONCPP_LIB_BUILD_SHARED=OFF -G "Unix Makefiles" ../..
make
change
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/lib/release/ -ljson
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/lib/debug/ -ljson
else:unix: LIBS += -L$$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/lib/ -ljson
INCLUDEPATH += $$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/include
DEPENDPATH += $$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/include
for this:
unix|win32: LIBS += -ljsoncpp
and ready to use jsoncpp

Adding External libraries to QT 5.1.1 project

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?