Changes between Version 23 and Version 24 of CompilationGuide/MSVC


Ignore:
Timestamp:
Jun 4, 2017, 12:50:17 AM (2 years ago)
Author:
TarmoPikaro
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CompilationGuide/MSVC

    v23 v24  
    1 FFmpeg can be built on Windows with Visual Studio. The [https://www.ffmpeg.org/platform.html#Microsoft-Visual-C_002b_002b-or-Intel-C_002b_002b-Compiler-for-Windows official guide] is quite clear, but a little bit out-of-date.
     1FFMpeg can be built with Visual studio solutions and projects, all you need to do is to svn checkout following svn repository:
    22
    3 FFmpeg can be built with MSVC 2012 or earlier using a C99-to-C89 conversion utility and wrapper, or with MSVC 2013 or later natively.
     3https://sourceforge.net/p/vlc2/
    44
    5 You will need the following prerequisites:
     5It'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.
    66
    7 * [https://github.com/libav/c99-to-c89/ C99-to-C89 Converter & Wrapper] if using MSVC 2012 or earlier.
    8 * [http://code.google.com/p/msinttypes/ msinttypes] if using MSVC 2012 or earlier.
    9 * [http://www.mingw.org/ MSYS]
    10 * [http://yasm.tortall.net/ YASM]
    11 
    12 First, you need to unzip and copy the prerequisites into a folder, for example, `c:\c99`.
    13 
    14 Then, you need to add the folder `c:\c99` into your `PATH` environment variable.
    15 
    16 Rename the yasm executable you will use to `yasm.exe`.
    17 
    18 Finally, create an `INCLUDE` environment variable, and point it to `c:\c99`; this is the location where the compiler will find `inttypes.h`.
    19 
    20 {{{
    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 [http://www.faqforge.com/windows/fix-the-program-cant-start-because-msvcr100-dll-is-missing-from-your-computer-error-on-windows/ redistributable].
    23 }}}
    24 
    25 == Setting the environment ==
    26 
    27 In 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
    28 the tools.
    29 
    30 In 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.
    31 
    32 This 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 }}}
    34 
    35 To build 64bit you need to run this command to enable the 64bit compiler and linker:
    36 {{{
    37 vcvarsall.bat amd64
    38 }}}
    39 
    40 Installed in the Visual Studio `VC` directory (for example: `C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC`).
    41 Depending on the system the argument might be `x86_amd64` or similar.
    42 
    43 See the following link for details: [https://msdn.microsoft.com/en-us/library/x4d2c09s.aspx]
    44 
    45 Finally, to set up a proper MSYS environment, you need to run `msys.bat` (or the equivalent `mingw32_shell.bat`) from the command prompt.
    46 
    47 Now, 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:
    48 {{{
    49 export PATH="/c/Program Files (x86)/Microsoft Visual Studio 12.0/VC/BIN/":$PATH
    50 }}}
    51 
    52 or when building for 64bit
    53 
    54 {{{
    55 export PATH="/c/Program Files (x86)/Microsoft Visual Studio 12.0/VC/BIN/amd64/":$PATH
    56 }}}
    57 
    58 or removing or renaming the `link` binary provided by MSYS.
    59 
    60 Next, 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.
    61 
    62 
    63 == Build ==
    64 
    65 Finally, run:
    66        
    67 For MSVC:
    68 
    69 {{{
    70 ./configure --toolchain=msvc
    71 make
    72 make install
    73 }}}
    74 
    75 or the following:
    76 
    77 {{{
    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
    79 }}}
    80 
    81 
    82 `--enable-shared` will generate the dynamic linked lib (dlls)
    83 
    84 {{{
    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`.
    87 }}}
    88 
    89 {{{
    90 cl is unable to create an executable file.
    91 If cl is a cross-compiler, use the --enable-cross-compile option.
    92 Only do this if you know what cross compiling means.
    93 C compiler test failed.
    94 }}}
    95 
    96 You 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 [https://trac.ffmpeg.org/ticket/3203 #3203 Windows MSVC configure failed].
    97 
    98 The right `link.exe` should come from this location:
    99 
    100 {{{
    101 /c/Program Files (x86)/Microsoft Visual Studio 12.0/VC/BIN/link.exe
    102 }}}
    103 
    104 or in the case of 64bit builds
    105 
    106 {{{
    107 /c/Program Files (x86)/Microsoft Visual Studio 12.0/VC/BIN/amd64/link.exe
    108 }}}
    109 
    110 You might see three problems when building `ffmpeg`:
    111 
    112 1. `pr` command not found:
    113 
    114 A solution is posted at [http://creekcodes.blogspot.com/2011/02/msys-pr-not-found.html MSYS pr not found]. Basically, `pr.exe` is removed from MSYS. You need to [http://sourceforge.net/projects/mingw/files/MSYS/Base/msys-core/_obsolete/coreutils-5.97-MSYS-1.0.11-2/coreutils-5.97-MSYS-1.0.11-snapshot.tar.bz2/download download] it and copy `pr.exe` to the `msys/bin` folder.
    115 
    116 2. 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.
    117 
    118 In 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.
    119 
    120 3. `common.mak:140: *** missing separator.  Stop.`
    121 
    122 This 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.
    123 
    124 How to build debug version?
    125 
    126 An example:
    127 
    128 {{{
    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
    130 }}}
    131 
    132 
    133 == Compiling FFmpeg with external libraries ==
    134 
    135 In 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.
    136 
    137 Also, you may need to compile the libraries themselves with VC in order to make it possible to link them when building the FFmpeg DLLs.
    138 
    139 The 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).
    140 
    141 === libx264 ===
    142 
    143 The following example command will configure libx264:
    144 {{{
    145 CC=cl ./configure --enable-shared --prefix=<PREFIX> --extra-cflags="-DNO_PREFIX"
    146 make
    147 make install-lib-shared
    148 }}}
    149 
    150 The `NO_PREFIX` flag may be necessary to make linkable libraries.
    151 
    152 
    153 === libopenh264 ===
    154 
    155 libopenh264 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.
    156 The following command will build the openh264 library with VC:
    157 {{{
    158 make OS=msvc PREFIX=<PREFIX> install
    159 }}}
     7Simplest way is to copy *.cs (scripts) and *.exe (tools) from that repository, apply necessary changes and open vlc.sln and build it.