I have QT installed in my PC, which is using the Visual Studio 2010 compiler
I tested this with a simple hello world application, and it works fine.
However now I am trying to use OpenCV with QT. I have installed Visual Studio 2010 express and professional both, and opencv works fine there. But, when I try to run the OpenCV in QT, I get the following error
main.obj:-1: error: LNK2019: unresolved external symbol "public: void __thiscall cv::Mat::deallocate(void)" (?deallocate#Mat#cv##QAEXXZ) referenced in function "public: void __thiscall cv::Mat::release(void)" (?release#Mat#cv##QAEXXZ)
main.obj:-1: error: LNK2019: unresolved external symbol "void __cdecl cv::fastFree(void *)" (?fastFree#cv##YAXPAX#Z) referenced in function "public: __thiscall cv::Mat::~Mat(void)" (??1Mat#cv##QAE#XZ)
main.obj:-1: error: LNK2019: unresolved external symbol "int __cdecl cv::waitKey(int)" (?waitKey#cv##YAHH#Z) referenced in function _main
main.obj:-1: error: LNK2019: unresolved external symbol "void __cdecl cv::imshow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class cv::_InputArray const &)" (?imshow#cv##YAXABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##ABV_InputArray#1##Z) referenced in function _main
main.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall cv::_InputArray::_InputArray(class cv::Mat const &)" (??0_InputArray#cv##QAE#ABVMat#1##Z) referenced in function _main
main.obj:-1: error: LNK2019: unresolved external symbol "void __cdecl cv::namedWindow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" (?namedWindow#cv##YAXABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##H#Z) referenced in function _main
main.obj:-1: error: LNK2019: unresolved external symbol "class cv::Mat __cdecl cv::imread(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" (?imread#cv##YA?AVMat#1#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##H#Z) referenced in function _main
release\FirstProject.exe:-1: error: LNK1120: 7 unresolved externals
Following is my FirstProject.pro file's content
#-------------------------------------------------
#
# Project created by QtCreator 2013-04-26T11:15:33
#
#-------------------------------------------------
QT += core
QT -= gui
TARGET = FirstProject
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += C:\opencv\build\include\
LIBS += -LC:\opencv\build\x86\vc10\lib \
-lopencv_calib3d240d.lib\
-lopencv_contrib240d.lib\
-lopencv_core240d.lib\
-lopencv_features2d240d.lib\
-lopencv_flann240d.lib\
-lopencv_gpu240d.lib\
-lopencv_haartraining_engined.lib\
-lopencv_highgui240d.lib\
-lopencv_imgproc240d.lib\
-lopencv_legacy240d.lib\
-lopencv_ml240d.lib\
-lopencv_nonfree240d.lib\
-lopencv_objdetect240d.lib\
-lopencv_photo240d.lib\
-lopencv_stitching240d.lib\
-lopencv_ts240d.lib\
-lopencv_video240d.lib\
-lopencv_videostab240d.lib
I tried by chainging to the following FirstProject.pro content, but no good at all
#-------------------------------------------------
#
# Project created by QtCreator 2013-04-26T11:15:33
#
#-------------------------------------------------
QT += core
QT -= gui
TARGET = FirstProject
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += C:\opencv\build\include\
LIBS += -LC:\opencv\build\x86\vc10\lib \
-lopencv_core240 \
-lopencv_highgui240 \
-lopencv_imgproc240 \
-lopencv_features2d240 \
-lopencv_calib3d240
Following is my code
main.cpp
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat image = imread("D:/Tulips.jpg");
if(!image.data)
{
cout << "Error loading image" << endl;
}
else
{
namedWindow("Image");
imshow("Image",image);
}
waitKey(0);
return 0;
}
Why am I getting this error?
QT Project files try to handle file/directory separators uniformly, ie, forward v's back slashes. It shouldn't matter which is used. However, maybe there's some translation going on.
Try replacing all backslashes '\' with forward versions '/'. Qmake will convert them appropriately.
Replace with -LC:/opencv/build/x86/vc10/lib
It also might be the final backslash on your INCLUDEPATH that's the problem. Maybe it's joining up next line?
I found the answer. The only way to remove the issue is adding the libs one by one, with the complete path
LIBS += C:/opencv/build/x86/vc9/lib/opencv_calib3d240.lib
LIBS += C:/opencv/build/x86/vc9/lib/opencv_contrib240.lib
I had the same problem but I found the answer nowhere. after 8 days trying to fix it finally I found the answer and I want to share it with u.
when u use static linking opencv first check if your libraries are really static linked , to do so open a developer command prompt msvc , navigate into your libraries path , and type the command bellow :
lib /LIBS opencv_world.lib
rather than opencv_world.lib you can put any other library names.
then check there were only refrenced .obj files in it , so that means u can use this library static.
then remember when u use static lib in opencv , u need to at some other libraries to ur project that in dynamic linking u didnt need to. these libraries are in your library directory that their name doesnt start with opencv.
u can see some of them bellow :
IlmImf.lib
ippicvmt.lib
ippiw.lib
ittnotify.lib
libjasper.lib
libtiff.lib
libwebp.lib
zlib.lib
remeber , If u got the error "couldnt find library" , use the exact path to add it. for example :
LIBS += E:\opencv\build-x86-static\install\x86\vc15\staticlib\zlib.lib
Related
I use Qt Add-in in my project. But i dont understand , what i do uncorrect.
My .pro file:
QT += core gui network
TEMPLATE = app
TARGET = MMworker
DESTDIR = ../Debug
CONFIG += debug
LIBS += -L"../../../../boost_1_70_0/stage/lib"
DEPENDPATH += .
MOC_DIR += .
OBJECTS_DIR += debug
UI_DIR += .
RCC_DIR += .
Get a lot of errors. For example
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall QHostAddress::QHostAddress(void)" (__imp_??0QHostAddress##QAE#XZ) referenced in function...
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: bool __thiscall QHostAddress::setAddress(class QString const &)" (__imp_?setAddress#QHostAddress##QAE_NABVQString###Z) referenced in function ...
Error LNK2019 unresolved external symbol "public: void __thiscall TcpServer::connectToServer(class QHostAddress,int)" (?connectToServer#TcpServer##QAEXVQHostAddress##H#Z) referenced in function...
Error LNK2019 unresolved external symbol "public: bool __thiscall MainTimer::timeAfterMomentExceeds(__int64,__int64)" (?timeAfterMomentExceeds#MainTimer##QAE_N_J0#Z) referenced in function ...
Error LNK2019 unresolved external symbol "private: __int64 __thiscall MainTimer::getMilliseconds(void)" (?getMilliseconds#MainTimer##AAE_JXZ) referenced in function "public: __int64 __thiscall MainTimer::time_ms(void)" (?time_ms#MainTimer##QAE_JXZ)...
Error LNK2019 unresolved external symbol "public: void __thiscall Channel::readData(class QString &)" (?readData#Channel##QAEXAAVQString###Z) referenced in function ...
Error LNK2001 unresolved external symbol "public: virtual void * __thiscall SimpleDevice::qt_metacast(char const *)" (?qt_metacast#SimpleDevice##UAEPAXPBD#Z)...
P.S.: Also I look in qt simple tcp communication with ui projects . I dont understand how I can "You need to enable modules you're using in Qt Project Settings".
UPD1: compile was sucsess, but build still falling.
Error was in inlcude additional dependensies(removed) and included dirs(added)
I'm building a project using Qt Creator, which at the same time, using QuickFIX library. When I try to build the project using MSVC 2015 32bits build, it always has these two kinds of linker error:
error: LNK2019: unresolved external symbol "private: static double __cdecl FIX::DoubleConvertor::fast_strtod(char const *,int,int *)" (?fast_strtod#DoubleConvertor#FIX##CANPBDHPAH#Z) referenced in function "public: static bool __cdecl FIX::DoubleConvertor::convert(class
std::basic_string,class std::allocator > const &,double &)" (?convert#DoubleConvertor#FIX##SA_NABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##AAN#Z)
error: LNK2001: unresolved external symbol "private: static double __cdecl FIX::DoubleConvertor::fast_strtod(char const *,int,int *)" (?fast_strtod#DoubleConvertor#FIX##CANPBDHPAH#Z
But I'm not using these double convertor anywhere in my project and I thought the quickfix library should have export all function from its source.
I've tried it on 64bits or MSVC 2017 build, nothing works..
I've been trying these for several weeks... It's driving me crazy
edit: my .pro file:
DEPENDPATH += $$(QuickFIX_VS2017)/include/quickfix
INCLUDEPATH += $$(QuickFIX_VS2017)/include/quickfix
Debug:LIBS += -L$$(QuickFIX_VS2017)/x64/Debug/ -lquickfix
Debug:PRE_TARGETDEPS += $$(QuickFIX_VS2017)/x64/Debug/quickfix.lib
Release:LIBS += -L$$(QuickFIX_VS2017)/x64/Release -lquickfix
Release:PRE_TARGETDEPS += $$(QuickFIX_VS2017)/x64/Release/quickfix.lib
This question has already been asked here, but since I have many more details to provide, I think it is best to start with a new question.
I have trouble linking the ImageMagick lib files in my program that uses the Visual Studio MSVC 2015 compiler. Here are the steps I have followed:
I have compiled the static MT runtimes by using the "configure.exe" utility and built in Visual Studio the solution it generated, "VisualStaticMT.sln". This creates lib files such as "CORE_RL_Magick++_.lib" in C:\ImageMagick-6.9.3-2\VisualMagick\lib.
In my C++11 program, the configuration relevant to ImageMagick is (I use QtCreator, but with the MSVC2015 compiler):
INCLUDEPATH += \
C:\ImageMagick-6.9.3-2\ImageMagick\Magick++\lib \
C:\ImageMagick-6.9.3-2\ImageMagick
LIBS += \
-lC:\ImageMagick-6.9.3-2\VisualMagick\lib\CORE_RL_Magick++_ \
-lC:\ImageMagick-6.9.3-2\VisualMagick\lib\CORE_RL_wand_ \
-lC:\ImageMagick-6.9.3-2\VisualMagick\lib\CORE_RL_magick_
QMAKE_CXXFLAGS += \
-DMAGICKCORE_HDRI_ENABLE=0 \
-DMAGICKCORE_QUANTUM_DEPTH=16
A piece of the program contains:
#include <Magick++.h>
...
Magick::Image img;
img = Magick::Image(filename);
When compiling I get link errors:
movie.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Magick::Image::Image(void)" (__imp_??0Image#Magick##QAE#XZ) referenced in function "public: __thiscall Frame<unsigned char>::Frame<unsigned char>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0?$Frame#E##QAE#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z)
movie.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Magick::Image::Image(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0Image#Magick##QAE#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function "public: __thiscall Frame<unsigned char>::Frame<unsigned char>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0?$Frame#E##QAE#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z)
movie.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall Magick::Image::~Image(void)" (__imp_??1Image#Magick##UAE#XZ) referenced in function "public: __thiscall Frame<unsigned char>::Frame<unsigned char>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0?$Frame#E##QAE#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z)
movie.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class Magick::Image & __thiscall Magick::Image::operator=(class Magick::Image const &)" (__imp_??4Image#Magick##QAEAAV01#ABV01##Z) referenced in function "public: __thiscall Frame<unsigned char>::Frame<unsigned char>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0?$Frame#E##QAE#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z)
movie.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall Magick::Image::write(long,long,unsigned int,unsigned int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,enum MagickCore::StorageType,void *)" (__imp_?write#Image#Magick##QAEXJJIIABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##W4StorageType#MagickCore##PAX#Z) referenced in function "public: __thiscall Frame<unsigned char>::Frame<unsigned char>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0?$Frame#E##QAE#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z)
movie.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: struct MagickCore::_Image const * __thiscall Magick::Image::constImage(void)const " (__imp_?constImage#Image#Magick##QBEPBU_Image#MagickCore##XZ) referenced in function "public: __thiscall Frame<unsigned char>::Frame<unsigned char>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0?$Frame#E##QAE#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z)
release\corr.exe : fatal error LNK1120: 6 unresolved externals
The "dllimport" error suprises me, as I think there should be no DLL involved with the "static MT runtimes" I am using.
Any idea on how I could solve the problem?
Thanks.
EDIT
A few more things I have tried:
Linking the libraires with the lines below in main.cpp gave the same errors:
#pragma comment(lib, "CORE_RL_Magick++_.lib")
#pragma comment(lib, "CORE_RL_wand_.lib")
#pragma comment(lib, "CORE_RL_magick_.lib")
I tried to add all the 27 lib files located in C:\ImageMagick-6.9.3-2\VisualMagick\lib. If I exclude CORE_RL_exr_.lib, I get the same error. If I include it, I get additional errors that suggest this file should not be added:
CORE_RL_exr_.lib(IexBaseExc.obj):-1: error: LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in main.obj
probably you are missing some library files. because your program is unable to link library file that's why it gives linker error. Try to link lib file externally .. try this code before main method..
#pragma comment(lib, "CORE_DB_magick++.lib")
you can download this lib file from given below link.
https://github.com/moravianlibrary/Open-DPI-Detector/tree/master/OpenDpiDetector/Libraries/ImageMagick-6.7.6/VisualMagick/lib
To be able to link your app with static build of ImageMagick you have to do couple of tricks (as for ImageMagick-7.0.8-11):
add preprocessor definition STATIC_MAGICK to your visual studio project
add missing input library CORE_DB_croco_.lib/CORE_RL_croco_.lib in the Linker->Input (other libs ImageMagick adds automatically via #pragma)
rename CORE_XX_liblzma_.pdb -> CORE_XX_lzma_.lib (ImageMagick links this lib with other name, probably bug), XX = RL or DB
The answer to linking the ImageMagick static libraries is to ensure you link all the dependant static libraries as well!
Once you have compiled the solution for ImageMagick static libraries, go to the 'VisualMagick' folder (within the ImageMagick cloned repository) then to to the 'lib' folder there you will see all the *_DB_*.lib and *_RL_*.lib files for Debug and Release.
You need to include those names in the 'Additional Dependencies' section for both Release and Debug.
Another key aspect is to ensure the libraries are built by the same compiler for the same platform architecture as your own application .. (WIN32 or x64).
I'm new and trying to use Quazip under qt 5.5. So I just downloaded project sources from http://quazip.sourceforge.net/ and opened .pro file. When I try to build project I 've got multiple errors:
C1083: Cannot open include file: 'zlib.h': No such file or directory
To avoid building zlib on windows I just installed (from here: http://gnuwin32.sourceforge.net/packages/zlib.htm) complete pack for windows in C:\GnuWin32. Then I added this line in .pro file:
INCLUDEPATH += C:\GnuWin32\include
This generated another error:
Cannot open include file: 'unistd.h': No such file or directory
But changing this line
#if 1 /* HAVE_UNISTD_H -- this line is updated by ./configure */
into this fixed the problem.
#if HAVE_UNISTD_H
Unfortunately now I get 25 unresolved external symbols, some of them:
quaadler32.obj:-1: error: LNK2019: unresolved external symbol adler32 referenced in function "public: virtual unsigned int __cdecl QuaAdler32::calculate(class QByteArray const &)" (?calculate#QuaAdler32##UEAAIAEBVQByteArray###Z)
quacrc32.obj:-1: error: LNK2019: unresolved external symbol crc32 referenced in function "public: virtual unsigned int __cdecl QuaCrc32::calculate(class QByteArray const &)" (?calculate#QuaCrc32##UEAAIAEBVQByteArray###Z)
unzip.obj:-1: error: LNK2001: unresolved external symbol crc32
quagzipfile.obj:-1: error: LNK2019: unresolved external symbol gzopen referenced in function "private: void * __cdecl QuaGzipFilePrivate::open(class QString const &,char const *)" (?open#QuaGzipFilePrivate##AEAAPEAXAEBVQString##PEBD#Z)
quaziodevice.obj:-1: error: LNK2019: unresolved external symbol deflateInit_ referenced in function "public: virtual bool __cdecl QuaZIODevice::open(class QFlags<enum QIODevice::OpenModeFlag>)" (?open#QuaZIODevice##UEAA_NV?$QFlags#W4OpenModeFlag#QIODevice#####Z)
quaziodevice.obj:-1: error: LNK2019: unresolved external symbol inflate referenced in function "protected: virtual __int64 __cdecl QuaZIODevice::readData(char *,__int64)" (?readData#QuaZIODevice##MEAA_JPEAD_J#Z)
I tries adding this line:
LIBS += -LC:\GnuWin32\lib
But that didn't solve the problem. WHat is the easiest way to use Quazip under Qt?
Download quazip source from quzip site
Open by Qt Creator quazip.pri
Replace all strings #include "zlib.h" or "#include < zlib.h>"
to
#include <QtZlib/zlib.h>
Build project and run unit tests.
I want to get Allegro 4 (MSCV 9) to work with Qt Creator. I am using Windows XP.
I have added these lines to my .pro:
INCLUDEPATH += C:/Allegro/include \
LIBS += C:/Allegro/lib/allegro-4.4.2-md.lib \
C:/Allegro/lib/allegro-4.4.2-monolith-md.lib \
C:/Allegro/lib/allegrogl-0.4.4-md.lib \
C:/Allegro/lib/loadpng-1.5-md.lib \
My code looks like this:
#include <iostream>
#include <allegro.h>
volatile int closedWindow = false;
void CloseButtonCallback() {closedWindow = true;}
END_OF_FUNCTION(CloseButtonCallback())
int main()
{
allegro_init();
set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 400, 300, 0, 0);
set_window_title("Testing");
LOCK_FUNCTION(closeButtonCallback)
set_close_button_callback(CloseButtonCallback);
while(!closedWindow){}
allegro_exit();
return 0;
}
END_OF_MAIN()
And I keep getting errors like these, when I try to compile:
main.obj:-1: error: LNK2019: unresolved external symbol imp__allegro_exit referenced in function "int __cdecl _mangled_main(void)" (?_mangled_main##YAHXZ)
main.obj:-1: error: LNK2019: unresolved external symbol _imp_set_close_button_callback referenced in function "int __cdecl _mangled_main(void)" (?_mangled_main##YAHXZ)
main.obj:-1: error: LNK2019: unresolved external symbol _imp_set_window_title referenced in function "int __cdecl _mangled_main(void)" (?_mangled_main##YAHXZ)
main.obj:-1: error: LNK2019: unresolved external symbol _imp_set_gfx_mode referenced in function "int __cdecl _mangled_main(void)" (?_mangled_main##YAHXZ)
main.obj:-1: error: LNK2019: unresolved external symbol _imp_set_color_depth referenced in function "int __cdecl _mangled_main(void)" (?_mangled_main##YAHXZ)
main.obj:-1: error: LNK2019: unresolved external symbol __imp_install_allegro_version_check referenced in function "int __cdecl _mangled_main(void)" (?_mangled_main##YAHXZ)
I'm using precompiled Allegro 4.4 for MinGW from http://www.allegro.cc/files/. I merged those three folders (bin, include, lib) inside the archive to MinGW folder which has same folders as well. Then added LIBS += liballegro-4.4.2-mt to .pro file and everything works fine.
Looks like you have to use the GCC-compiled version of Allegro for Qt.
Something like
LIBS +="path_to_allegro_for_mingw/lib/liballegro-4.4.2-md.a"
GCC uses different name mangling and different export libraries, so even while you're using the Allegro dlls, MSVC-compiled .lib wouldn't work.