Congratulations to our 2022 Qt Champions!

Linker error caused by Qt qjpeg4

  • I cannot link my project because of some issues with the qjpeg4 library.

    Its DLL is located here:


    I get this linker error:

    @Linking CXX executable test.exe
    CMakeFiles\test.dir/objects.a(entrypoint.cpp.obj):entrypoint.cpp:(.text.startup+0x2692): undefined reference to `qt_plugin_instance_qjpeg()'
    collect2: ld returned 1 exit status

    In the file containing main() I have: @Q_IMPORT_PLUGIN(qjpeg)@

    I tried adding these lines, with no improvement:

    @QApplication app(argc, argv);
    QString sDir = QCoreApplication::applicationDirPath();
    app.addLibraryPath(sDir + "/plugins");@

    The previous error should even not depend on the fact that the DLL has not been found, since it is still in the link phase...

    If in the file containing main() I remove Q_IMPORT_PLUGIN(qjpeg), the linker is successful, but the executable does absolutely nothing.

    The only Qt headers I include are <QApplication> and <QtPlugin>; adding <QtGui> has been useless.

    I am using cmake, and this is the token of my CMakeLists.txt file relative to Qt:

    @find_package(Qt4 REQUIRED)
    set(useQt_HEADERS )
    set(useQt_SOURCES entrypoint.cpp source.cpp)
    target_link_libraries(myProject ${QT_LIBRARIES} )

  • Please remove all the jpg-plugin related code from your source file and pro file.

    It's a plugin, and it will be automatically load by your application.

  • All I could remove from my code was:

    @QString sDir = QCoreApplication::applicationDirPath();
    app.addLibraryPath(sDir + "/plugins");@

    In CMakeLists.txt there is nothing related to the qjpg4 plugin, just general Qt stuff.
    In the file containing the main() function, I #include <QtPlugin>.
    Same behaviour.

  • Please remove the following code you added too.


  • I removed

    Now it links.

    When I launch the executable (both from the command line and from the GUI), I get absolutely nothing. The main() function is not even entered. No error messages either.

Log in to reply