Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#4764 closed enhancement (wontfix)

Problems when compiling with msvc toolchain and with other libraries.

Reported by: David Sterkehus Owned by:
Priority: wish Component: build system
Version: git-master Keywords: MSVC
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:

  1. The library tests can't work with cl.exe.
  2. Runtime library specification is necessary even for static builds.

(See last section for details)

How to reproduce:

% vcvarsall.bat
% export LIB="X:\pathto\externlibs\lib;$LIB"
% export INCLUDE="X:\pathto\externlibs\include;$INCLUDE"
# MT, with no msvcrt DLL
% ffmpeg -i input ... output
./configure --toolchain=msvc --enable-gpl --enable-nonfree --enable-nvenc --enable-libvorbis --enable-libmp3lame --enable-libtheora --enable-libx264 --enable-libx265 --enable-libxvid --enable-static --disable-shared --disable-debug --extra-cflags="-MD" --extra-cxxflags="-MD" --extra-ldflags="/nodefaultlib:libcmt.lib" --extra-libs="libmp3lame-static.lib libtheora_static.lib libxvidcore.lib zlib.lib libmpghip-static.lib libvorbis_static.lib x265-static.lib libogg_static.lib libx264.lib"
# MD, with msvcrt
./configure --toolchain=msvc --enable-gpl --enable-nonfree --enable-nvenc --enable-libvorbis --enable-libmp3lame --enable-libtheora --enable-libx264 --enable-libx265 --enable-libxvid --enable-static --disable-shared --disable-debug --extra-cflags="-MT" --extra-cxxflags="-MT" --extra-ldflags="/nodefaultlib:msvcrt.lib" --extra-libs="libmp3lame-static.lib libtheora_static.lib libxvidcore.lib zlib.lib libmpghip-static.lib libvorbis_static.lib x265-static.lib libogg_static.lib libx264.lib"

MSVC compiles just fine when it compiles just ffmpeg it self. But when it comes to compile with other libraries enabled, it goes into chaos.

  1. The library tests when using MSVC toolchain

The script builds test programs for enabled libraries to check if they are available with the given toolchain. For example, to see libmp3lame, it compiles following code:

#include <lame/lame.h>

int main(){
lame_set_VBR_quality();
return 0;
}

specified by configure script line:

enabled libmp3lame        && require "libmp3lame >= 3.98.3" lame/lame.h lame_set_VBR_quality -lmp3lame

The problem is, link.exe somehow doesn't know what to link and complains with error. Yes, the full prototype for the function is:

int lame_set_VBR_quality(lame_global_flags *, float)

Removing these checks(see attachment) solves this problem and the compilation never fails under the circumstance that libraries are properly set in LIB and INCLUDE vars.

  1. Runtime library links

MSVC toolchain links what runtime library to use when COMPILE TIME, NOT link time. So /MD and /MT switches are in compiler settings not in linker settings.
If you have to link MT on your program that links ffmpeg-libs, linking ffmpeg-libs compiled with /MD won't work because of the external libraries. Linking will fail. You need to link MT version of ffmpeg-lib for MT programs or DLLs and vice versa.
As you can see on the "How to reproduce" section, you can compile and link MT as mentioned and the other libraries that ffmpeg uses.

If someone could fix these problems, we could use use MSVC to compile ffmepg freely, without using painful mingw toolchains.

Attachments (1)

configure.no_checks.patch (5.1 KB ) - added by David Sterkehus 9 years ago.
Patch to make configure script to skip library checks.

Download all attachments as: .zip

Change History (10)

by David Sterkehus, 9 years ago

Attachment: configure.no_checks.patch added

Patch to make configure script to skip library checks.

comment:1 by Hendrik, 9 years ago

This works just fine if your libraries are named properly, and wouldn't be named something-static.lib, which is not a name configure checks for, and not standard names these libs distribute as usually.

comment:2 by Hendrik, 9 years ago

Regarding MT and MD, well its a known fact that mixing these can lead to troubles, there is nothing we can do to change how the compiler and linker work, so I'm not sure what you are trying to achieve?

comment:3 by David Sterkehus, 9 years ago

Yees. But still, "libmpghip.lib" is missing which comes with libmp3lame static build. I compiled Lame with VC, and libmpghip.lib is needed to work with libmp3lame.lib.
Those '--extra-libs' options were merely for my convenience.

And for rumtimes, I wish there could be "--msvc-runtime=msvcrt" and "--msvc-runtime=libcmt". I didn't mean to "mix" them. As I mentioned, you can't link MD linked libraries into MT linked program or DLL. The libraries will conflict(msvcrt.lib and libcmt.lib). I just wanted a ffmpeg.exe that doesn't require VC++ redist to run. With /MD switch on, you can't build one.

Should I make another ticket?

comment:4 by Hendrik, 9 years ago

MT is the default mode, you shouldn't need to specify anything to get a statically linked dll without vcredist deps.

in reply to:  4 comment:5 by David Sterkehus, 9 years ago

Two things, please:

  1. "libmpghip.lib" (-lmpghip). It's definite one.
  2. linking x265 (not 264)

Wrong example, sorry.
As you know x265 is C++ project, /MD is default config even if ENABLE_SHARED is unchecked on CMake dialog.
Its result IS static, except the runtimes parts linked to mscvrt. Here's the fuzz i've been trying to tell: How do I build /MD linked static ffmpeg-libs? I can't with currnet configure script. "--disable-shared" will make /MD disappear.
The other way around is fine. Everything's statically linked? every library's happy. MD static libraries? ... That's why I wish to have 'runtime spec'.

Does this explain now?
Thanks, by the way, for your replies.

Replying to heleppkes:

MT is the default mode, you shouldn't need to specify anything to get a statically linked dll without vcredist deps.

comment:6 by Hendrik, 9 years ago

I'm confused, I thought you didn't want vcredist deps, so why would you want /MD static libraries?

We can't "fix" external libraries. You should consult with x265 and ask them how to build a static library with /MT, so that it can be linked with ffmpeg without any problems.

comment:7 by David Sterkehus, 9 years ago

That was one hell long conversion of "We wont do that"

comment:8 by David Sterkehus, 9 years ago

Resolution: wontfix
Status: newclosed

comment:9 by Carl Eugen Hoyos, 9 years ago

Keywords: toolchain removed
Type: defectenhancement
Note: See TracTickets for help on using tickets.