Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot link library FFMpeg on Windows #350

Open
hamlatzis opened this issue Oct 6, 2022 · 8 comments
Open

cannot link library FFMpeg on Windows #350

hamlatzis opened this issue Oct 6, 2022 · 8 comments

Comments

@hamlatzis
Copy link

I have build the library using visual studio and now I want to use it in ffmpeg

Downloaded the source code of ffmpeg and according to documentation for Windows I have to build it under msys2
I can configure ffmpeg and successfully build everything when not enabling kvazaar; but when I try this

../../configure --toolchain=msvc --arch=x86_64 --enable-shared --enable-static --enable-cross-compile --enable-libkvazaar --target-os=win32 --extra-cflags="-MD -DWINAPI_FAMILY=WINAPI_FAMILY_APP -D_WIN32_WINNT=0x0A00" --extra-ldflags="-APPCONTAINER WindowsApp.lib" --prefix=../../Build/Windows10

I get "ERROR: kvazaar >= 0.8.1 not found using pkg-config", which I think is logical since under windows there is no package file

@fador
Copy link
Member

fador commented Oct 6, 2022

It might be related to the issue with pkg-config that also prevents me from building ffmpeg using the media-autobuild suite: m-ab-s/media-autobuild_suite#2298
The pkg-config should work in msys2 just fine.

@hamlatzis
Copy link
Author

It might be related to the issue with pkg-config that also prevents me from building ffmpeg using the media-autobuild suite: m-ab-s/media-autobuild_suite#2298 The pkg-config should work in msys2 just fine.

ok, but as far as I know VS doesn't create pkg-config ".pc" files, So what's the solution?

@fador
Copy link
Member

fador commented Oct 7, 2022

oh right, I didn't realise that, but you can basically just create it manually from src/kvazaar.pc.in 😅

Typically in linux kvazaar.pc looks like:

prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
incdir=${prefix}/include

Name: libkvazaar
Description: Open-source HEVC encoder
Version: 2.1.0
Libs: -L${libdir} -lkvazaar
Libs.private: -lpthread -lm   -lrt
Cflags: -I${incdir}

@fador
Copy link
Member

fador commented Oct 10, 2022

So I was messing around with things a bit and the proper way to do this might be to build Kvazaar also in msys2.

Since our scripts are not really built for msvc, you need to sed some stuff to make it compatible.
Here's how I could do a static build, running this as kvazaar.sh (assuming you have the msvc ready in the system):

sed -i 's/-Wall -Wextra -Wvla -Wno-sign-compare -Wno-unused-parameter//g' configure.ac
sed -i 's/ -ftree-vectorize -fvisibility=hidden//g' configure.ac
sed -i 's/KVZ_CFLAGS=\"/KVZ_CFLAGS=\"-DKVZ_STATIC_LIB -I.\/threadwrapper\/include\/ -I ..\/include\//g' configure.ac
sed -i 's/-I\$srcdir\/src/-I ./g' configure.ac

sed -i 's/AX_PTHREAD(/#AX_PTHREAD(/g' configure.ac
sed -i 's/PTHREAD_CFLAGS=-pthread//g' configure.ac
sed -i 's/PTHREAD_LIBS=-lpthread//g' configure.ac
sed -i 's/libkvazaar_la_SOURCES =/libkvazaar_la_SOURCES = \\\n\tthreadwrapper\/src\/pthread.cpp \\\n\tthreadwrapper\/src\/semaphore.cpp/g' src/Makefile.am
sed -i 's/kvazaar_SOURCES =/kvazaar_SOURCES = extras\/getopt.c /g' src/Makefile.am
sed -i 's/CFLAGS=\"\$PTHREAD_CFLAGS \$CFLAGS\"/CPPFLAGS=\"\$CFLAGS\"/g' configure.ac
sed -i 's/CC=\"\$PTHREAD_CC\"//g' configure.ac

./autogen.sh
LD=link.exe CC=cl ./configure --enable-static
make
make install

..for shared build just remove the --enable-static and change -DKVZ_STATIC_LIB to -DKVZ_DLL_EXPORTS

I hope this helps

@fador
Copy link
Member

fador commented Oct 11, 2022

Here's a full code to compile Kvazaar + ffmpeg in msys2:
https://gist.github.com/fador/19c4eee37a0cfd80dcc01434bbea8765

@hamlatzis
Copy link
Author

@fador it worked like a charm, tried both methods (manually and the scripts you've provided)

@pinbraerts
Copy link

Workaround the pkg-config on MinGW:
--pkg-config=true --extra-cflags="-I$PATH_TO_KVAZAAR_INCLUDES -DKVZ_STATIC_LIB" --extra-ldflags="-libpath:$PATH_TO_KVAZAAR_LIBS kvazaar.lib"

@vtorri
Copy link
Contributor

vtorri commented Apr 15, 2024

isn't this bug resolved ? I have no problem with mingw, ffmpeg is built with kvazaar support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants