wang-bin / QtAV

A cross-platform multimedia framework based on Qt and FFmpeg. 基于Qt和FFmpeg的跨平台高性能音视频播放框架. Recommand to use new sdk https://github.com/wang-bin/mdk-sdk
http://qtav.org
3.99k stars 1.51k forks source link

Build with qt 5.12.1 and msvc2017 #1193

Open KirillShirkunov opened 5 years ago

KirillShirkunov commented 5 years ago

QtAV, Qt version and platform

QtAV 1.12.0, qt 5.12.1 (x86/x64), windows 10, msvc2017

Reproduction steps

Build QtAV from QtCreator, then run sdk_install.bat.

Expected behavior

Project should be builded. Actually, this version QtAV was builded from sources with qt 5.9.0 and msvc2015. and project was successfully compiled with it.

Actual behavior

When I try to compile my app, there are some errors from linker:

AVFilterConfigPage.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: static class QStringList __cdecl QtAV::LibAVFilter::videoFilters(void)" (__imp_?videoFilters@LibAVFilter@QtAV@@SA?AVQStringList@@XZ) referenced in function "public: __thiscall AVFilterConfigPage::AVFilterConfigPage(class QWidget *)" (??0AVFilterConfigPage@@QAE@PAVQWidget@@@Z)

Log of compile for demo app

C:\Qt\Tools\QtCreator\bin\jom.exe -f Makefile.Debug
    cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -Zi -MDd -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc /Fddebug\test.vc.pdb -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_AVWIDGETS_LIB -DQT_AV_LIB -DQT_OPENGL_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I..\test -I. -I..\..\..\Qt\5.12.1\msvc2017\include -I..\..\..\Qt\5.12.1\msvc2017\include\QtAVWidgets -I..\..\..\Qt\5.12.1\msvc2017\include\QtAV -I..\..\..\Qt\5.12.1\msvc2017\include\QtOpenGL -I..\..\..\Qt\5.12.1\msvc2017\include\QtWidgets -I..\..\..\Qt\5.12.1\msvc2017\include\QtGui -I..\..\..\Qt\5.12.1\msvc2017\include\QtANGLE -I..\..\..\Qt\5.12.1\msvc2017\include\QtCore -Idebug -IC:\VulkanSDK\1.0.51.0\include -I..\..\..\Qt\5.12.1\msvc2017\mkspecs\win32-msvc -Fodebug\ @C:\Users\kirill\AppData\Local\Temp\main.obj.13360.0.jom
main.cpp
    link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:debug\test.exe @C:\Users\kirill\AppData\Local\Temp\test.exe.13360.1516.jom
main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QtAV::AVPlayer::AVPlayer(class QObject *)" (__imp_??0AVPlayer@QtAV@@QAE@PAVQObject@@@Z) referenced in function _main
main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QtAV::AVPlayer::~AVPlayer(void)" (__imp_??1AVPlayer@QtAV@@UAE@XZ) referenced in function _main
debug\test.exe : fatal error LNK1120: 2 unresolved externals

Sample files (optional)

Demo project test.zip

nejatafshar commented 5 years ago

I have the same problem with Qt 5.12.1 on Windows. It was okay with Qt 5.12 but since upgrading to 5.12.1 my app linked to QtAV with QT += av gives unresolved external symbol error where ever i have used QtAV. I have checked and all QtAV files are properly installed in Qt directory.

nejatafshar commented 5 years ago

I have tested with Qt 5.12.2 and the problem exists. I managed to solve it by linking to QtAV lib directly via: LIBS += -L$$QT.core.libs -lQtAV1

KirillShirkunov commented 5 years ago

Great solution, thanks! Maybe there is known what was changed in Qt 5.12.x?

nejatafshar commented 5 years ago

I have no idea what could cause this problem. But it's clear that something is preventing QtAV from being known as a module named av.

javlada commented 5 years ago

Thank you very much, this solved my problem. I use MinGW version of Qt and had the same problem, so it is related to Qt version, not the compiler.

However in my case the problem isn't solved completely. My app now compiles but crashes at runtime. I expect it can not load the libraries. How did you solve this?

Also in my case I had to modify the line LIBS += -L$$QT.core.libs -lQtAV1 to LIBS += -L$$QT.core.libs -lQtAV

Thank you

nejatafshar commented 5 years ago

@javlada Try to copy QtAV and FFmpeg DLL files alongside your app exe.

javlada commented 5 years ago

@nejatafshar Yes, this solves the problem, but why do I have to do it if the libraries are in the same directory as other Qt libraries?

nejatafshar commented 5 years ago

@javlada QtAV files are in Qt libs directory when it's built and installed. But FFmpeg files are not. You could also copy them in Qt dir to enable your apps run in Qt creator. Anyway you should copy QtAV and FFmpeg files alongside your app exe when deploying it.

javlada commented 5 years ago

@nejatafshar Also the ffmpeg files are int Qt lib directory. I copy them there when compiling QtAV. It wouldn't compile without them (or I would need to specify the path in QtAV). For deploying it is clear that I have to include all the libraries I use.

javlada commented 5 years ago

Now I run into a problem when compiling for Android. For Windows build I just copy all the needed QtAV libraries to the "release" directory where my .exe file is compiled. But how do I do it with Android build?

nejatafshar commented 5 years ago

@javlada For android you should add the pathes for FFmpeg files built for the specific android architecture to ANDROID_EXTRA_LIBS in your pro file :

ANDROID_EXTRA_LIBS = \
    PathToFFmpegFiles/libavcodec.so \
    PathToFFmpegFiles/libavdevice.so \
    PathToFFmpegFiles/libavfilter.so \
    PathToFFmpegFiles/libavformat.so \
    PathToFFmpegFiles/libavutil.so \
    PathToFFmpegFiles/libswresample.so \
    PathToFFmpegFiles/libswscale.so

This way they would be bundled in the apk using androiddeployqt tool.