MSVC static builds currently always use ".a" for static library suffixes
(e.g. libavcodec.a, libavformat.a). This causes failures when linking
with Visual Studio, which expects ".lib" static libraries.
This patch adjusts configure so that when --toolchain=msvc is used,
LIBSUF is correctly set to ".lib" instead of the Unix default ".a".
This fixes linking with MSVC and Visual Studio-based build systems.
---
Environment:
- Windows 10
- MSYS2 (mingw64)
- Visual Studio 2019 / 2022
- NASM installed
- MSVC toolchain selected
Commands:
./configure --toolchain=msvc --enable-static --disable-shared
make
Resulting static libraries incorrectly have ".a" suffix, e.g.:
libavcodec.a
libavformat.a
libavutil.a
Linking test program with MSVC:
cl test_ffmpeg.c /I C:\ffmpeg-test-install\include ^
/link /LIBPATH:C:\ffmpeg-test-install\lib avcodec.lib avformat.lib
avutil.lib
Error:
LINK : fatal error LNK1181: cannot open input file 'avcodec.lib'
---
Verification of the fix:
After applying this patch and rebuilding:
Generated static libraries:
avcodec.lib
avformat.lib
avutil.lib
Test program build script (build_test.bat):
cl test_ffmpeg.c ^
/I C:\ffmpeg-test-install\include ^
/link /LIBPATH:C:\ffmpeg-test-install\lib ^
avcodec.lib avformat.lib avutil.lib
Output:
D:\ffmpeg\temp>.\buid_test.bat
Microsoft (R) C/C++ Optimizing Compiler Version 19.50.35718 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
test_ffmpeg.c
Microsoft (R) Incremental Linker Version 14.50.35718.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:test_ffmpeg.exe
/LIBPATH:C:\ffmpeg-test-install\lib
avcodec.lib
avformat.lib
avutil.lib
/OUT:test.exe
test_ffmpeg.obj
=== BUILD SUCCESS ===
Running test...
FFmpeg avcodec version: 4068196
FFmpeg avformat version: 4064871
FFmpeg avutil version: 3936868
This confirms MSVC accepts the .lib suffix and the libraries function
correctly.
---
configure | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/configure b/configure
index 47f9b31439..596d66ce53 100755
--- a/configure
+++ b/configure
@@ -6067,7 +6067,7 @@ case $target_os in
win32|win64)
disable symver
LIBPREF=""
- LIBSUF=".lib"
+ LIBSUF=".lib"
if enabled shared; then
# Cannot build both shared and static libs with MSVC or icl.
disable static
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]