<SOLVED>Program only works if .DLL extension is left off

  • Have built a simple OpenCV program to display a photo. It only works if I leave the .dll extensions** off **of its Library listing in the pro. file:
    Won't run:
    LIBS += -LC:\\OpenCV-2.3.1\\bin\ -lopencv_core2411.dll \ -lopencv_highgui2411.dll \ -lopencv_imgproc2411.dll \ -lopencv_features2d2411.dll \ -lopencv_calib3d2411.dll
    Will execute:
    LIBS += -LC:\\OpenCV-2.3.1\\bin\ -lopencv_core2411\ -lopencv_highgui2411\ -lopencv_imgproc2411 \ -lopencv_features2d2411 \ -lopencv_calib3d2411
    Adding to the oddity, a few of these DLL files have only partial names that work.
    For example DLL: opencv_imgproc2411 still links the file without the lib in front of the opencv...libopencv_imgproc2411

  • Linkage where LIBS are used require *.lib ( extension is added automatically ) files not dlls.

    *.lib files are either statically linked libraries or interface to appropriate dll which resolves calls to exported functions.

    dlls are needed only during execution of application.

  • Ok, that seems logical. Why is it working anyway with a path to the dlls. Since there are no lib files there shouldn't it throw an error...or does it treat the dll file as a lib one since there is no dll extension?

  • Moderators

    No. There is definitely a difference between dll and lib. Not everywhere the extension .lib is used. MinGW uses .a

  • Ok! I found the library files *.dll.a and included them in the build. I specified the files themselves. I posted the correct code below, one pro file in unix and win.

    correct unix
    QT       += core
    QT       -= gui
    TARGET = untitled17a
    CONFIG   += console
    CONFIG   -= app_bundle
    TEMPLATE = app
    SOURCES += main.cpp \
    INCLUDEPATH += C:/OpenCV-2.3.1/install/include
    LIBS += -LC:/OpenCV-2.3.1/lib/ -llibopencv_core2411.dll.a (Unix)
    LIBS += C:/OpenCV-2.3.1/lib/  libopencv_highgui2411.dll.a (win32)
    HEADERS += \

    If I had 20 library files how would I handle that? Import library through QT Creator?

  • I thought I had it until I tried a test using a bogus extension...:(

    LIBS += -LC:/OpenCV-2.3.1/lib/ -llibopencv_core2411.dll.x

    Besides I only have 2 directories dll and dll.a

    Built just fine, a bad good thing.

    Executable runs fine outside of qt.

  • Moderators

    That it is not running with Qt creator framework might be an issue with size. However, I have no experience with opencv.

    When you use external dlls, respectively dlls in general, you link stubs, much smaller libs, to your code. The stubs have all information for using the dlls lateron. With the naming and which libs to link to your code you need to check with opencv. With MinGW you can rename the libs and sometimes people do this. This is in contrast to MS where the libs are always called *.lib as far as I collect.

    Another thing you are refering to the complete path to libs in one string. That is possble on Windows. However, in case you migrate lateron to Linux or MacOS you need to use the separate notation. It might be helpful to get used to it directly. Checkout LIBS parameter. There is also a summary on third party libs.

  • I think I misstated myself --

    LIBS += -LC:/OpenCV-2.3.1/lib/ -llibopencv_core2411.dll.x

    The .x extension was a test for a false positive: the library executed successfully with a madeup .x extension.

    It is just confusing. I'm trying to make sure everything is running ok.

    Additionally, I think it sage advice to build cross platform compatibility starting now. I have studied the link above, and it mentions windows and Unix. Where do I get information about coding the other platforms in qmake?

    Overall, based on what you are saying, the .pro file can manage the compatibilties but you only have to write one program - that's the beauty of Qt?

  • Lifetime Qt Champion


    Basically you should have something like:

    win32:LIBS += -LC:/OpenCV-2.3.1/lib/
    LIBS += -lopencv_core2411

    And that should be enough, win32 will scope the line so it'll only get executed for windows target. You can then add scopes for your other target OS to setup the correct path to OpenCV

Log in to reply

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