Problem compiling ffmpeg with nvenc using visual studio 2015 community edition

I’m trying to build ffmpeg w/ nvenc on Windows 10 64 bit and visual studio 2015 community edition. The command from step 10 in the Using FFmpeg with NVIDIA GPU Hardware Acceleration doc:

./configure --enable-nonfree --enable-cuda-sdk --enable-libnpp –-toolchain=msvc --extra-cflags=-I…/nv_sdk --extraldflags=-libpath:…/nv_sdk

Gives me the error ‘Unknown option “–-toolchain=msvc”’

Background: I’ve executed the commands (changed the path in the first, I’m not sure its right):

export PATH=“/C/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/”:$PATH export PATH=“/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0/bin/”:$PATH

And …/nv_sdk has the subdirectories include & bin, copied from the NVIDIA GPU Computing Toolkit directory.

Did you solve this? I am facing this problem too.

First write the command ./configure --toolchain=msvc. After configuration has finished, run the configuration again like this: ./configure -toolchain=msvc --enable-cuda-nvcc --enable-nonfree --enable-libnpp --extra-cflags=-I…/nv_sdk --extraldflags=-libpath:…/nv_sdk. Do not use –enable-cuda-sdk, it has been deprecated. There will be error again. Modify the configure file in the main directory. Search for the word gencode in the file. You will see a line like this: nvccflags_default=“-gencode arch=compute_30,code=sm_30 -O2”. Replace 30 by converting your gpu’s compute capability version. FOR EXAMPLE: if your gpu has compute capability 6.1 then replace 30 with 61.

Thank you for sharing the solution and I’d like to mention that there are some typos in the command.
In the second command:
-toolchain=msvc
should be

--toolchain=msvc

I do NOT think you need to run the following first if the typo in the second command is fixed:
./configure --toolchain=msvc

And this forum editor may changed
DotDot
to some weird … unicode character, be careful when you copy them. (The ones next to libpath and extra-cflags

The command works for me:
./configure --enable-cuda-nvcc --disable-shared --enable-nonfree --enable-libnpp --toolchain=msvc --extra-cflags=-I../nv_sdk --extra-ldflags=-libpath:../nv_sdk

The gencode comment really helped me a lot. I changed it to 61 as I’m using GTX 1080 and its compute capability is 6.1
and you can find yours here: CUDA GPUs - Compute Capability | NVIDIA Developer

In my case, I proceeded as follows. I’m using visual studio 2019.
Please comment if you know how to fix it.


msys2_shell.cmd -mingw64

export PATH=“/c/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/”:$PATH
export PATH=“/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.2/bin/”:$PATH

$ which cl
/c/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl

$ cd nv-codec-header
$ make install PREFIX=/usr

$ cd..
$ cd ffmpeg

$ ./configure --enable-cuda-sdk --disable-shared --enable-nonfree --enable-libnpp --toolchain=msvc --extra-cflags=-I../nv_sdk --extra-ldflags=-libpath:../nv_sdk

The cl.exe error occurs as shown below.

cl.exe is unable to create an executable file.
If cl.exe is a cross-compiler, use the --enable-cross-compile option.
Only do this if you know what cross compiling means.
C compiler test failed.

If you think configure made a mistake, make sure you are using the latest
version from Git. If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC ffmpeg on irc.freenode.net.
Include the log file “ffbuild/config.log” produced by configure as this will help
solve the problem.

My Error Log as shown below.

test_ld cc
test_cc
BEGIN ./ffconf.fLNB2Hzt/test.c
1 int main(void){ return 0; }
END ./ffconf.fLNB2Hzt/test.c
cl.exe -nologo -I../nv_sdk -c -Fo./ffconf.fLNB2Hzt/test.o ./ffconf.fLNB2Hzt/test.c
test.c
./compat/windows/mslink -libpath:../nv_sdk -nologo -out:./ffconf.fLNB2Hzt/test.exe ./ffconf.fLNB2Hzt/test.o
LINK : error LNK2001: mainCRTStartup 외부 기호를 확인할 수 없습니다.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\lib\x86\LIBCMT.lib : warning LNK4272: ‘X86’ 라이브러리 컴퓨터 종류가 ‘x64’ 대상 컴퓨터 종류와 충돌합니다.
./ffconf.fLNB2Hzt/test.exe : fatal error LNK1120: 1개의 확인할 수 없는 외부 참조입니다.
C compiler test failed.

Hello,
I’m also trying today to compile with Visual Studio 2019 and every time I have the following error:

MINGW64 ~/ffmpeg
$ ./configure --toolchain=msvc
cl.exe is unable to create an executable file.
If cl.exe is a cross-compiler, use the --enable-cross-compile option.
Only do this if you know what cross compiling means.
C compiler test failed.

If you think configure made a mistake, make sure you are using the latest
version from Git. If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file “ffbuild/config.log” produced by configure as this will help
solve the problem.

Please help.

I did everything else recommended by xywhpanda, even changed the gencode, but always getting the same error

from the log I see this:
WARNING: Unknown C compiler cl.exe, unable to select optimal CFLAGS
test_ld cc
test_cc
BEGIN ./ffconf.A0M5rfxR/test.c
1 int main(void){ return 0; }
END ./ffconf.A0M5rfxR/test.c
cl.exe -c -o ./ffconf.A0M5rfxR/test.o ./ffconf.A0M5rfxR/test.c
./configure: line 983: cl.exe: command not found
C compiler test failed.

Hello,
I am getting the same error and have not found any solution online. Have you found one?

–-toolchain=msvc wrong spell before toolchain

Hi,

I’ve followed this guide to install cuda-nvcc and libnpp with ffmpeg.
I’m on Windows 10, running msys2 and mingw64, with a GTX 1080.
This guide is outdated for me, on certain parts at least.
This reply is my attempt to help others to compile, with a couple of questions at the end.

Corrections to the compilation guide:

  1. the path to the bin folder of the NVIDIA GPU Computing Toolkit is directly added to the path as you can see it in the Environement variables when installating it:
    Capture

  2. the path to the Visual studio 12 might be correct but not for Visual studio 2019:
    export PATH="/c/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.29.30037/bin/Hostx64/x64":$PATH

Btw is it still relevant to have a guide which uses Microsoft Visual Studio 12.0 for windows?

  1. As pointed out in the commonly faced issues and tips to resolve them, i am running mingw64 :
    Open the x64 Native Tools Command Prompt for VS 2017 :
cd C:\dev\msys64
msys2_shell.cmd -mingw64 -use-full-path

And also passing the correct flags corresponding to my graphic card to nvcc :

--nvccflags="-gencode arch=compute_52,code=sm_52 -O2"

I have also passed the extra --extra-ldflags to the linker like this : --extra-ldflags=-libpath:"PathToStuff" ( as pointed here too).

  1. I have renamed the mingw64 linker to avoid confusion with MSVC linker :
mv /usr/bin/link.exe /usr/bin/link.exe.bak
# then
which link
#gives me
/c/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.29.30037/bin/Hostx64/x64/link
  1. ('ve copied the content of the folders:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include to C:\dev\msys64\ThirdParty\ffmpeg\nv_sdk\include
and
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\lib\x64 to C:\dev\msys64\ThirdParty\ffmpeg\nv_sdk\lib

Using 1) to 5), I’ve configured FFmpeg version 4.3.3 with the following:
Open the x64 Native Tools Command Prompt for VS 2017 :

cd C:\dev\msys64
msys2_shell.cmd -mingw64 -use-full-path

In the mingw64 shell :

cd /ThirdParty/ffmpeg/FFmpeg-n4.3.3
 ./configure \
--toolchain=msvc \
--prefix="/ThirdParty/ffmpeg/ffmpeg_build" \
--target-os=mingw64 \
--arch=x86_64 \
--extra-ldflags=-libpath:"/ThirdParty/ffmpeg/nv_sdk/lib" \
--extra-cflags=-I"/ThirdParty/ffmpeg/nv_sdk/include" \
--nvccflags="-gencode arch=compute_52,code=sm_52 -O2" \
--toolchain=msvc \
--enable-cuda-nvcc \
--enable-libnpp \
--enable-shared \
--enable-avresample \
--pkg-config=pkg-config \
--disable-debug \
--disable-w32threads \
--enable-dxva2 \
--enable-d3d11va \
--enable-nonfree \
--enable-gpl \
--disable-doc \
--logfile=config.log

How can I compile FFmpeg with more flags such as those:


--enable-libopencore_amrwb \
--enable-libopenjpeg \
--enable-libopus \
--enable-librtmp \
--enable-libsoxr \
--enable-libspeex \
--enable-libsrt \
--enable-libtheora \
--enable-libvorbis \
--enable-libx264 \
--enable-libx265 \
--enable-libxvid \
--enable-libvpx \
--enable-libwebp \
--enable-libxml2 \
--enable-openal \
--enable-pic \
--enable-postproc \
--enable-runtime-cpudetect \
--enable-swresample \
--enable-version3 \
--enable-vulkan \
--enable-zlib \

Is using msvc it seems like it’s not possible to include them straight.
Do I need to recompile them individually?

Best,

P

You can build any lib you want for msvc toolchin with visual studio and vcpkg very easy :

Required:
Git.
visual studio.
Just Run visual studio native x64 command line , redirect to any folder you want , then run :

git clone GitHub - microsoft/vcpkg: C++ Library Manager for Windows, Linux, and MacOS

cd vcpkg

bootstrap-vcpkg.bat

Done.

Now to build for example static libopus for msvc toolchin, just run :

vcpkg install --triplet=x64-windows-static opus

For static x264 just run :
vcpkg install --triplet=x64-windows-static x264
For static x265 just run ;
vcpkg install --triplet=x64-windows-static x265

To search any lib or pkg , just run :

vcpkg search libUwant

ok will give it a go soon and report here.

That’s the right answer , the spell is --toolchain=msvc not –-toolchain=msvc .
wrong Dash before toolchain

Ok, I have tested it and it works, using release:

For example :

vcpkg --triplet=x64-windows-release install libvorbis  --debug

Great tool, and great tip @rroben27 .

However, had to patch openssl with this patch and x265 with my own :

In the configure file of the FFmpeg install:

# enabled libx265           && require_pkg_config libx265 x265 x265.h x265_api_get &&
#                              require_cpp_condition libx265 x265.h "X265_BUILD >= 70"
enabled libx265           && { check_pkg_config libx265 x265 "stdint.h x265.h" x265_api_get ||
                                { require libx265 "stdint.h x265.h" x265_api_get "-llibx265 $pthreads_extralibs $libm_extralibs" &&
                                warn "using libx265 without pkg-config"; } } &&
                             require_cpp_condition libx265 x265.h "X265_BUILD >= 70"