Strange Linker error LNK2019 MSVC2013-64 bits build dbg/rel with linkage to opencv 3.00 prebuilt library (.lib static 64-bits) on Win10/64bits



  • I extracted the OpenCV v3.00 to the C:\opencv3.0\ directory of my Win10/64bits Desktop PC and this package bundles pre-built static libraries (.lib) files for both x86 and x64 Windows Desktop platfrom.

    When I create a Qt Quick Application project in Qt 5.5 I choose desktop Qt 5.5.0 MSVC2013 64bit Kit Selection for both dbg and rel.
    In fact the OpenCV prebuild static libraries reside in "C:\opencv3.0\build\x86\vc12\staticlib" and "C:\opencv3.0\build\x64\vc12\staticlib".
    and those libraries are compiled with VC2012 but my Kit Selection is MSVC2013, that I guess is not the issue with my linkage error (LNK2019).
    I set following .pro file (so it would be 64/32 bit friendly by writing as follows.

     TEMPLATE = app
    
    QT += qml quick widgets
    SOURCES += main.cpp \
    	OpenCVExm.cpp
    
    RESOURCES += qml.qrc
    #unix:LIBS += -L/usr/local/lib -lmath
    #LIBPATH += C:\\opencv3.0\\build\\x86\\vc12\\staticlib
    
    CONFIG( debug, debug|release ) {
    win32:contains(QMAKE_HOST.arch, x86_64){
    
    	LIBS += -LC:/opencv3.0/build/x64/vc12/staticlib/
    		-llibjpegd
    		-lopencv_core300d
    		-lopencv_calib3d300d
    		-lopencv_contrib300d
    		-lopencv_features2d300d
    		-lopencv_flann300d
    		-lopencv_gpu300d
    		-lopencv_haartraining_engined
    		-lopencv_highgui300d
    		-lopencv_imgproc300d
    		-lopencv_legacy300d
    		-lopencv_ml300d
    		-lopencv_nonfree300d
    		-lopencv_objdetect300d
    		-lopencv_photo300d
    		-lopencv_stitching300d
    		-lopencv_superres300d
    		-lopencv_ts300d
    		-lopencv_video300d
    		-lopencv_videostab300d
    
    } else {
    
    	LIBS += -LC:/opencv3.0/build/x86/vc12/staticlib/
    		-llibjpegd
    		-lopencv_core300d
    		-lopencv_calib3d300d
    		-lopencv_contrib300d
    		-lopencv_features2d300d
    		-lopencv_flann300d
    		-lopencv_gpu300d
    		-lopencv_haartraining_engined
    		-lopencv_highgui300d
    		-lopencv_imgproc300d
    		-lopencv_legacy300d
    		-lopencv_ml300d
    		-lopencv_nonfree300d
    		-lopencv_objdetect300d
    		-lopencv_photo300d
    		-lopencv_stitching300d
    		-lopencv_superres300d
    		-lopencv_ts300d
    		-lopencv_video300d
    		-lopencv_videostab300d
    	}
    }
    
    
    
    INCLUDEPATH +="C:/opencv3.0/build/include"
    
    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =
    
    # Default rules for deployment.
    include(deployment.pri)
    
    HEADERS += \
    	opencvexm.hpp
    

    And my project file (OpenCVExm.cpp/hpp) are as follow (very simple)

    OpenCVExm.cpp :

    #include "opencv2/core/core.hpp"
    #include "opencv2/highgui/highgui.hpp"
    #include <iostream>
    using namespace cv;
    using namespace std;
    int testOpenCV(void){
    	   namedWindow("MyWindow", CV_WINDOW_AUTOSIZE);
    	   return 0;
    }
    

    and opencvexm.hpp:

    #ifndef OPENCVEXM_HPP
    #define OPENCVEXM_HPP
    int testOpenCV(void);
    #endif // OPENCVEXM_HPP
    

    and the main.cpp file contents is:

    #include <QApplication>
    #include <QQmlApplicationEngine>
    #include "opencvexm.hpp"
    
    int main(int argc, char *argv[])
    {
    	QApplication app(argc, argv);
    
    	QQmlApplicationEngine engine;
    	engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    	testOpenCV();
    	return app.exec();
    }
    

    I tried following test/builds and before every build I cleaned the project then run qmake and lastly rebuild all the project.

    Even I tried to compile with Desktop MSVC2013 64bit Debug mode with following qmake command:
    qmake.exe "C:\OpenCV3\MyLearning\Qt Project\HW1\HW1\HW1.pro" -r -spec win32-msvc2013 "CONFIG+=debug" "CONFIG+=declarative_debug" "CONFIG+=qml_debug"

    and the release build as follows:

    qmake.exe "C:\OpenCV3\MyLearning\Qt Project\HW1\HW1\HW1.pro" -r -spec win32-msvc2013

    and I always get following linker error regardless of 32/64 dbg/rel

    OpenCVExm.obj:-1: error: LNK2019: unresolved external symbol "private: char * __cdecl cv::String::allocate(unsigned __int64)" (?allocate@String@cv@@AEAAPEAD_K@Z) referenced in function "public: __cdecl cv::String::String(char const *)" (??0String@cv@@QEAA@PEBD@Z)
    
    OpenCVExm.obj:-1: error: LNK2019: unresolved external symbol "private: void __cdecl cv::String::deallocate(void)" (?deallocate@String@cv@@AEAAXXZ) referenced in function "public: __cdecl cv::String::~String(void)" (??1String@cv@@QEAA@XZ)
    

    3 unresolved externals, I think I included all the required libraries but I do not know why I get linker error.

    I am wondering if win32:contains is only used for the 32 bit apps or it does not matter 32/64 bits platfrom, and how can I fix this problem.
    Please note that I included the debug libraries (their names end with 'd') ,do they need .pdb files included in the project!?
    Thanks


  • Moderators

    Usually on Windows you cannot mix different compilers, even not different versions of VC. So, this is most probably the issue.
    Try to build OpenCV with MSVC2013.



  • @jsulm
    I tried to re-build the OpenCV3.0 libraries in VisualStudio 2013 -64bits compiler environment
    and implement the freshly built static libraries an I get similar error in Qt.

    I can not figure out what is wrong going on.


  • Moderators

    You can try to add your static libraries like this: LIBS += PATH_TO_LIB_DIR/libLIBNAME.lib



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.