Linker problem with QtAV
-
Hi,
I created a media player which uses QtAV for playback. Now I changed my computer and installed the whole toolchain from scratch and I can not compile it anymore. When I try to use QtAV, I get this linker error:
release/main.o:main.cpp:(.text+0x4fd): undefined reference to `_imp___ZN4QtAV8AVPlayerC1EP7QObject' release/main.o:main.cpp:(.text+0x1862): undefined reference to `_imp___ZN4QtAV8AVPlayerD1Ev' release/main.o:main.cpp:(.text+0x259f): undefined reference to `_imp___ZN4QtAV8AVPlayerD1Ev' collect2.exe: error: ld returned 1 exit status mingw32-make[2]: *** [Makefile.Muzika.Release:317: release/Muzika.exe] Error 1 mingw32-make[1]: *** [Makefile.Muzika:38: release] Error 2 mingw32-make: *** [Makefile:40: sub-Muzika-pro-make_first-ordered] Error 2 mingw32-make[2]: Leaving directory 'C:/Moje/QtProjects/build-MuzikaPlayer-Desktop_Qt_5_12_4_MinGW_32_bit-Release' mingw32-make[1]: Leaving directory 'C:/Moje/QtProjects/build-MuzikaPlayer-Desktop_Qt_5_12_4_MinGW_32_bit-Release' 09:46:13: The process "C:\Qt\Tools\mingw730_32\bin\mingw32-make.exe" exited with code 2. Error while building/deploying project MuzikaPlayer (kit: Desktop Qt 5.12.4 MinGW 32-bit) When executing step "Make"
I tried both 64bit and 32bit versions, reverted from Qt 5.13 to 5.12, reverted from QtAV 1.13 to 1.12. And still I have the same problem. Do you have any idea what might be wrong? The QtAV examples compile and work fine. But my app (and even a minimal example) don't.
Thank you.
-
Changing versions has nothing to do with this. Linker just can't find the definitions of the library's functions.
Since you said you changed computer make sure that the path to the QtAv library in your .pro file is still valid.
Please post contents of your .pro so we can take a look. -
The QtAV libraries are copied in Qt's installation folder. After compilation of QtAV there is a .bat file which does it. It looks like this:
mkdir C:\Qt\5.12.4\mingw73_32\include\QtAV\ copy /y C:\Moje\QtProjects\build-QtAV-Desktop_Qt_5_12_4_MinGW_32_bit-Release\lib_win_x86\*Qt*AV*.a* C:\Qt\5.12.4\mingw73_32\lib\ copy /y C:\Moje\QtProjects\build-QtAV-Desktop_Qt_5_12_4_MinGW_32_bit-Release\lib_win_x86\libQtAV5.a C:\Qt\5.12.4\mingw73_32\lib\libQt5AV.a copy /y C:\Moje\QtProjects\build-QtAV-Desktop_Qt_5_12_4_MinGW_32_bit-Release\lib_win_x86\libQtAVd5.a C:\Qt\5.12.4\mingw73_32\lib\libQt5AVd.a copy /y C:\Moje\QtProjects\build-QtAV-Desktop_Qt_5_12_4_MinGW_32_bit-Release\tools\install_sdk\mkspecs\features\av.prf C:\Qt\5.12.4\mingw73_32\mkspecs\features\av.prf copy /y C:\Moje\QtProjects\build-QtAV-Desktop_Qt_5_12_4_MinGW_32_bit-Release\tools\install_sdk\mkspecs\modules\qt_lib_av*.pri C:\Qt\5.12.4\mingw73_32\mkspecs\modules\ copy /y C:\Moje\QtProjects\build-QtAV-Desktop_Qt_5_12_4_MinGW_32_bit-Release\bin\Qt*AV*.dll C:\Qt\5.12.4\mingw73_32\bin\ mkdir C:\Qt\5.12.4\mingw73_32\include\QtAVWidgets\ copy /y C:\Moje\QtProjects\build-QtAV-Desktop_Qt_5_12_4_MinGW_32_bit-Release\lib_win_x86\*Qt*AV*.a* C:\Qt\5.12.4\mingw73_32\lib\ copy /y C:\Moje\QtProjects\build-QtAV-Desktop_Qt_5_12_4_MinGW_32_bit-Release\lib_win_x86\libQtAVWidgets5.a C:\Qt\5.12.4\mingw73_32\lib\libQt5AVWidgets.a copy /y C:\Moje\QtProjects\build-QtAV-Desktop_Qt_5_12_4_MinGW_32_bit-Release\lib_win_x86\libQtAVWidgetsd5.a C:\Qt\5.12.4\mingw73_32\lib\libQt5AVWidgetsd.a copy /y C:\Moje\QtProjects\build-QtAV-Desktop_Qt_5_12_4_MinGW_32_bit-Release\tools\install_sdk\mkspecs\features\avwidgets.prf C:\Qt\5.12.4\mingw73_32\mkspecs\features\avwidgets.prf copy /y C:\Moje\QtProjects\build-QtAV-Desktop_Qt_5_12_4_MinGW_32_bit-Release\tools\install_sdk\mkspecs\modules\qt_lib_avwidgets*.pri C:\Qt\5.12.4\mingw73_32\mkspecs\modules\ copy /y C:\Moje\QtProjects\build-QtAV-Desktop_Qt_5_12_4_MinGW_32_bit-Release\bin\Qt*AV*.dll C:\Qt\5.12.4\mingw73_32\bin\ copy /y C:\Moje\QtProjects\QtAV\tools\install_sdk\..\..\src\QtAV\*.h C:\Qt\5.12.4\mingw73_32\include\QtAV\ copy /y C:\Moje\QtProjects\QtAV\tools\install_sdk\..\..\src\QtAV\QtAV C:\Qt\5.12.4\mingw73_32\include\QtAV\ copy /y C:\Moje\QtProjects\QtAV\tools\install_sdk\..\..\widgets\QtAVWidgets\*.h C:\Qt\5.12.4\mingw73_32\include\QtAVWidgets\ copy /y C:\Moje\QtProjects\QtAV\tools\install_sdk\..\..\widgets\QtAVWidgets\QtAVWidgets C:\Qt\5.12.4\mingw73_32\include\QtAVWidgets\ mkdir C:\Qt\5.12.4\mingw73_32\include\QtAV\5.12.4\QtAV\ xcopy /s /q /y /i C:\Moje\QtProjects\QtAV\tools\install_sdk\..\..\src\QtAV\private C:\Qt\5.12.4\mingw73_32\include\QtAV\private xcopy /s /q /y /i C:\Moje\QtProjects\QtAV\tools\install_sdk\..\..\src\QtAV\private C:\Qt\5.12.4\mingw73_32\include\QtAV\5.12.4\QtAV\private xcopy /s /q /y /i C:\Moje\QtProjects\build-QtAV-Desktop_Qt_5_12_4_MinGW_32_bit-Release\bin\QtAV C:\Qt\5.12.4\mingw73_32\qml\QtAV copy /y C:\Moje\QtProjects\QtAV\tools\install_sdk\..\..\qml\plugins.qmltypes C:\Qt\5.12.4\mingw73_32\qml\QtAV\
Than i my .pro file I just add
QT += av
It has always worked without any problem. But now the linker can not find the libraries for some reason.
-
You have to rebuild QtAV with the same toolkit you're using and then install it to your toolkit directory using .bat file.
It's not just about the compiler, it's a combination of a compiler and Qt libraries.
QtAV build system is quite nice.Look through the compiler command line and flags, search for -l and -L keys, they specify linked library and additional library paths.
Make sure you've rerun qmake over your project file. I used to forget this and got the same compiler errors. -
You have to rebuild QtAV with the same toolkit you're using and then install it to your toolkit directory using .bat file.
It's not just about the compiler, it's a combination of a compiler and Qt libraries.
QtAV build system is quite nice.Look through the compiler command line and flags, search for -l and -L keys, they specify linked library and additional library paths.
Make sure you've rerun qmake over your project file. I used to forget this and got the same compiler errors. -
Very interesting. I went one more step back and reverted to Qt 5.11 and suddenly everything works fine.
So I'm thinking why it works perfectly with Qt 5.11 and fails in Qt 5.12 with the exactly same setup. The one thing I see as the main difference is the switch to new MinGW. But could this really be the problem?
The compiler command which fails is this:
g++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release\Muzika.exe @object_script.Muzika.Release -LC:\Moje\QtProjects\Muzika\3rdparty\taglib\lib\x64 -ltag -LC:\Moje\QtProjects\Muzika\3rdparty\mediainfo\lib\x64 -lmediainfo C:\Qt\5.13.0\mingw73_64\lib\libQt5Quick.a C:\Qt\5.13.0\mingw73_64\lib\libQt5Svg.a C:\Qt\5.13.0\mingw73_64\lib\libQt5Widgets.a C:\Qt\5.13.0\mingw73_64\lib\libQt5Multimedia.a C:\Qt\5.13.0\mingw73_64\lib\libQt5Gui.a C:\Qt\5.13.0\mingw73_64\lib\libQt5Qml.a C:\Qt\5.13.0\mingw73_64\lib\libQt5Network.a C:\Qt\5.13.0\mingw73_64\lib\libQt5Sql.a C:\Qt\5.13.0\mingw73_64\lib\libQt5Xml.a C:\Qt\5.13.0\mingw73_64\lib\libQt5Core.a release\muzika_res.o -lmingw32 C:\Qt\5.13.0\mingw73_64\lib\libqtmain.a -LC:\openssl\lib -LC:\Utils\postgresql\pgsql\lib -lshell32
If I run it from command line, I get exactly the same error message. Do you have any idea what could I check further and what could be the problem?
-
Hi,
By new, do you mean just the version or the architecture also ?
-
Did you ensure that all the libraries you are using in that project, are built with the same compiler ?
-
Yes, at least the QtAV libraries are definitely built with the same compiler, because I also build them in QtCreator with the same toolchain.
I found the solution here in QtAV discussion forum. According to the findings also from other people something has changed between Qt 5.11 and Qt 5.12, which breaks the functionality.
Now my application compiles but crashes immediately because some other libraries are missing. With Qt 5.11 the 3rd party libraries (in my case TagLib and MediaInfo) are automatically copied to release directory, but this also doesn't work with Qt 5.12+ anymore. I can fix this easily by copying the DLLs to the folder manually. But I mention it, because I think the two problems might be related.