Changes between Version 24 and Version 25 of CompilationGuide/MSVC

Jun 4, 2017, 12:53:58 AM (2 years ago)

Reverted to version 23.


  • CompilationGuide/MSVC

    v24 v25  
    1 FFMpeg can be built with Visual studio solutions and projects, all you need to do is to svn checkout following svn repository:
     1FFmpeg can be built on Windows with Visual Studio. The [ official guide] is quite clear, but a little bit out-of-date.
     3FFmpeg can be built with MSVC 2012 or earlier using a C99-to-C89 conversion utility and wrapper, or with MSVC 2013 or later natively.
    5 It's not most newest version of FFMpeg, but you can also port it to newer FFMpeg baselibe, by tracking what kind of changes were made to ffmpeg project itself.
     5You will need the following prerequisites:
    7 Simplest way is to copy *.cs (scripts) and *.exe (tools) from that repository, apply necessary changes and open vlc.sln and build it.
     7* [ C99-to-C89 Converter & Wrapper] if using MSVC 2012 or earlier.
     8* [ msinttypes] if using MSVC 2012 or earlier.
     9* [ MSYS]
     10* [ YASM]
     12First, you need to unzip and copy the prerequisites into a folder, for example, `c:\c99`.
     14Then, you need to add the folder `c:\c99` into your `PATH` environment variable.
     16Rename the yasm executable you will use to `yasm.exe`.
     18Finally, create an `INCLUDE` environment variable, and point it to `c:\c99`; this is the location where the compiler will find `inttypes.h`.
     21#!div style="border: 1pt dotted; margin: 1em; background-color: #fffff9;"
     22'''Note:''' If it complains of `MSVCR100.dll not found` when running yasm, install the Microsoft 2010 VC [ redistributable].
     25== Setting the environment ==
     27In order to build a program with the VisualStudio tools, you need to setup a proper environment in order to make sure that the configure and build system will be able to find
     28the tools.
     30In particular, the build system will use the `cl` compiler and the `link` linker bundled with the employed version of VisualStudio. In order to setup the enviroment it is so necessary to set the `PATH`, `LIB`, and `INCLUDE` variables to appropriate values.
     32This can be done by launching a `cmd.exe` native shell from the VisualStudio GUI. This can be done for example adding a tool from the Tools menu:
     33{{{ Tools -> External tools... -> Add }}}
     35To build 64bit you need to run this command to enable the 64bit compiler and linker:
     37vcvarsall.bat amd64
     40Installed in the Visual Studio `VC` directory (for example: `C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC`).
     41Depending on the system the argument might be `x86_amd64` or similar.
     43See the following link for details: []
     45Finally, to set up a proper MSYS environment, you need to run `msys.bat` (or the equivalent `mingw32_shell.bat`) from the command prompt.
     47Now, make sure that the `cl` and `link` program are not override by other programs with the same name from MSYS/MinGW (in particular, note that MinGW provides a program named `link`). In order to do so, you can set the MSYS path so that the VisualStudio tools are used instead, for example with the command:
     49export PATH="/c/Program Files (x86)/Microsoft Visual Studio 12.0/VC/BIN/":$PATH
     52or when building for 64bit
     55export PATH="/c/Program Files (x86)/Microsoft Visual Studio 12.0/VC/BIN/amd64/":$PATH
     58or removing or renaming the `link` binary provided by MSYS.
     60Next, make sure any other headers and libs you want to use, such as zlib, are located in a location that the compiler can see. Do so by modifying the `LIB` and `INCLUDE` environment variables to include the Windows-style paths to these directories. Alternatively, you can try and use the `--extra-cflags`/`--extra-ldflags` configure options.
     63== Build ==
     65Finally, run:
     67For MSVC:
     70./configure --toolchain=msvc
     72make install
     75or the following:
     78./configure --enable-asm --enable-yasm --arch=i386 --disable-ffserver --disable-avdevice --disable-swscale --disable-doc --disable-ffplay --disable-ffprobe --disable-ffmpeg --enable-shared --disable-static --disable-bzlib --disable-libopenjpeg --disable-iconv --disable-zlib --prefix=/c/ffmpeg --toolchain=msvc
     82`--enable-shared` will generate the dynamic linked lib (dlls)
     85#!div style="border: 1pt dotted; margin: 1em; background-color: #fffff9;"
     86'''Note:''' You might see an error saying cl can't generate executable; this is because you installed the `link.exe` from MSYS. It conflicts with the `link.exe` of Visual Studio. This can also indicate that you are mixing 64bit and 32bit versions of `cl.exe` and `link.exe`.
     90cl is unable to create an executable file.
     91If cl is a cross-compiler, use the --enable-cross-compile option.
     92Only do this if you know what cross compiling means.
     93C compiler test failed.
     96You can try `which link.exe` to verify if it is the case. If you see `/bin/link.exe`, then you can simply `rm /bin/link.exe`. For more info see [ #3203 Windows MSVC configure failed].
     98The right `link.exe` should come from this location:
     101/c/Program Files (x86)/Microsoft Visual Studio 12.0/VC/BIN/link.exe
     104or in the case of 64bit builds
     107/c/Program Files (x86)/Microsoft Visual Studio 12.0/VC/BIN/amd64/link.exe
     110You might see three problems when building `ffmpeg`:
     1121. `pr` command not found:
     114A solution is posted at [ MSYS pr not found]. Basically, `pr.exe` is removed from MSYS. You need to [ download] it and copy `pr.exe` to the `msys/bin` folder.
     1162. The compiler might complain about redefinition issues of `stdint.h`, because both msinttypes and Visual Studio have `stdint.h`. I removed `stdint.h` from `c:\c99` to let the compiler uses the one provided by Visual Studio.
     118In the end of configuration, you might also see `pkg-config` not found issue. That won't affect compilation, you can ignore it. It is said that installing `pkg-config` to MSYS is kinda tiresome.
     1203. `common.mak:140: *** missing separator.  Stop.`
     122This can happen if you try to build from a cloned git repository and have git configured to replace line endings in your local working copy. Be sure that you have the git option `core.autocrlf` set to `false` when cloning the git repo.
     124How to build debug version?
     126An example:
     129$ ./configure --enable-asm --enable-yasm --disable-ffserver --disable-avdevice --disable-doc --disable-ffplay --disable-ffprobe --disable-ffmpeg --enable-shared --disable-static --disable-bzlib --disable-libopenjpeg --disable-iconv --disable-zlib --prefix=/c/ffmpeg --toolchain=msvc --arch=amd64 --extra-cflags="-MDd" --extra-ldflags="/NODEFAULTLIB:libcmt" --enable-debug
     133== Compiling FFmpeg with external libraries ==
     135In order to build FFmpeg with support to external libraries, you need to make sure that the libraries and headers are placed in a location specified by the INCLUDE and LIB directories referenced by the VC compiler and linker. In case multiple libraries are used, you could use a common prefix to install all the libraries, so that you have to specify a single location.
     137Also, you may need to compile the libraries themselves with VC in order to make it possible to link them when building the FFmpeg DLLs.
     139The following subsections document how you can build some of the external libraries employed by FFmpeg using VC. Note that the setup step is the same for all the libraries (so it can be done just once, then you can build several libraries using the same MSYS terminal session).
     141=== libx264 ===
     143The following example command will configure libx264:
     145CC=cl ./configure --enable-shared --prefix=<PREFIX> --extra-cflags="-DNO_PREFIX"
     147make install-lib-shared
     150The `NO_PREFIX` flag may be necessary to make linkable libraries.
     153=== libopenh264 ===
     155libopenh264 provides no configuration system, so the build parameters have to be specified either by editing the Makefile, or by setting the parameters on the commandline.
     156The following command will build the openh264 library with VC:
     158make OS=msvc PREFIX=<PREFIX> install