[ffmpeg] build failure: cross compile from x64-linux to aarch64-linux
FFmpeg does not compile successfully when cross-compiling to aarch64-linux from x64-linux. If I understand correctly from my investigations, the problem seems to stem from an assumption in the portfile that if the target is arm64, we must be cross-compiling from a windows host machine.
See "Additional Context" section below for the results of my investigations.
Host Environment
- OS: Linux x64 Ubuntu 18.04
- Compiler: aarch64-linux-gnu-gcc (cross-compile from x64 Linux to aarch64)
To Reproduce Add triplet: aarch64-linux-dynamic.cmake
set(VCPKG_TARGET_ARCHITECTURE arm64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)
set(VCPKG_CMAKE_SYSTEM_NAME Linux)
# Note: Is this the right way to find the toolchain file?
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/../scripts/toolchains/aarch64-linux-cuda.cmake)
Add toolchain file:
cmake_minimum_required(VERSION 3.11)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
# specify the cross compiler
set(tools /usr/bin)
set(CMAKE_C_COMPILER ${tools}/aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER ${tools}/aarch64-linux-gnu-g++)
# where is the target environment
#set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# This assumes that pthread will be available on the target system
# (this emulates that the return of the TRY_RUN is a return code "0"
set(THREADS_PTHREAD_ARG "0"
CACHE STRING "Result from TRY_RUN" FORCE)
Run normal install:
./vcpkg install ffmpeg:aarch64-linux-dynamic
Failure logs
Replaced local path with XXXXX for privacy:
Command failed: /bin/bash --noprofile --norc XXXX/vcpkg/ports/ffmpeg/build_linux.sh XXXX/vcpkg/buildtrees/ffmpeg/aarch64-linux-dynamic-rel XXXX/vcpkg/buildtrees/ffmpeg/src/n4.2-02d8c63f80 XXXX/vcpkg/packages/ffmpeg_aarch64-linux-dynamic "--enable-asm --enable-yasm --disable-doc --enable-debug --enable-runtime-cpudetect --disable-openssl --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-libvpx --disable-libx264 --disable-opencl --disable-lzma --disable-bzlib --enable-avresample --enable-cuda --enable-nvenc --enable-cuvid --disable-libnpp --enable-cross-compile --target-os=win32 --arch=arm64 --disable-static --enable-shared "
Error code: 2
See logs for more information:
XXXX/vcpkg/buildtrees/ffmpeg/build-aarch64-linux-dynamic-rel-out.log
XXXX/vcpkg/buildtrees/ffmpeg/build-aarch64-linux-dynamic-rel-err.log
Contents of buildtrees/ffmpeg/build-aarch64-linux-dynamic-rel-err.log:
src/libavdevice/avdevice.c: In function ‘device_next’:
src/libavdevice/avdevice.c:88:13: warning: ‘av_oformat_next’ is deprecated [-Wdeprecated-declarations]
if (!(prev = av_oformat_next(prev)))
^~
In file included from src/libavdevice/avdevice.h:51:0,
from src/libavdevice/avdevice.c:23:
src/libavformat/avformat.h:2095:17: note: declared here
AVOutputFormat *av_oformat_next(const AVOutputFormat *f);
^~~~~~~~~~~~~~~
src/libavdevice/avdevice.c:92:13: warning: ‘av_iformat_next’ is deprecated [-Wdeprecated-declarations]
if (!(prev = av_iformat_next(prev)))
^~
In file included from src/libavdevice/avdevice.h:51:0,
from src/libavdevice/avdevice.c:23:
src/libavformat/avformat.h:2087:17: note: declared here
AVInputFormat *av_iformat_next(const AVInputFormat *f);
^~~~~~~~~~~~~~~
src/libavdevice/v4l2.c: In function ‘v4l2_get_device_list’:
src/libavdevice/v4l2.c:1054:58: warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 251 [-Wformat-truncation=]
snprintf(device_name, sizeof(device_name), "/dev/%s", entry->d_name);
^~
In file included from /usr/include/stdio.h:862:0,
from src/libavformat/avformat.h:316,
from src/libavformat/internal.h:27,
from src/libavdevice/v4l2-common.h:24,
from src/libavdevice/v4l2.c:35:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64:10: note: ‘__builtin___snprintf_chk’ output between 6 and 261 bytes into a destination of size 256
return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
__bos (__s), __fmt, __va_arg_pack ());
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/libavutil/aarch64/bswap.h: Assembler messages:
src/libavutil/aarch64/bswap.h:38: Error: no such instruction: `rev %ax,%ax'
src/libavutil/aarch64/bswap.h:38: Error: no such instruction: `rev %ax,%ax'
make: *** [libavformat/a64.o] Error 1
make: *** Waiting for unfinished jobs....
src/libavutil/aarch64/bswap.h: Assembler messages:
src/libavutil/aarch64/bswap.h:31: Error: no such instruction: `rev16 %ax,%ax'
src/libavutil/aarch64/bswap.h:38: Error: no such instruction: `rev %ax,%ax'
src/libavutil/aarch64/bswap.h:31: Error: no such instruction: `rev16 %ax,%ax'
src/libavutil/aarch64/bswap.h:38: Error: no such instruction: `rev %ax,%ax'
src/libavutil/aarch64/bswap.h:31: Error: no such instruction: `rev16 %ax,%ax'
src/libavutil/aarch64/bswap.h:38: Error: no such instruction: `rev %ax,%ax'
make: *** [libavformat/aacdec.o] Error 1
src/libavutil/aarch64/bswap.h: Assembler messages:
src/libavutil/aarch64/bswap.h:38: Error: no such instruction: `rev %ax,%ax'
src/libavutil/aarch64/bswap.h:38: Error: no such instruction: `rev %dx,%dx'
src/libavutil/aarch64/bswap.h:38: Error: no such instruction: `rev %dx,%dx'
src/libavutil/aarch64/bswap.h:38: Error: no such instruction: `rev %ax,%ax'
src/libavutil/aarch64/bswap.h:38: Error: no such instruction: `rev %ax,%ax'
src/libavutil/aarch64/bswap.h:38: Error: no such instruction: `rev %ax,%ax'
src/libavutil/aarch64/bswap.h:38: Error: no such instruction: `rev %ax,%ax'
make: *** [libavformat/aadec.o] Error 1
Additional context After some digging around, I located the source of the problem to this part of the portfile, line ~140:
if (VCPKG_TARGET_ARCHITECTURE STREQUAL "arm" OR VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64")
set(OPTIONS_CROSS " --enable-cross-compile --target-os=win32 --arch=${VCPKG_TARGET_ARCHITECTURE}")
vcpkg_find_acquire_program(GASPREPROCESSOR)
foreach(GAS_PATH ${GASPREPROCESSOR})
get_filename_component(GAS_ITEM_PATH ${GAS_PATH} DIRECTORY)
set(ENV{PATH} "$ENV{PATH};${GAS_ITEM_PATH}")
endforeach(GAS_PATH)
...
The code above seems to imply that if the target is arm or arm64, then we must be cross-compiling using Windows (sets --target-os=win32, among other things).
In my scenario, I am cross-compiling from Linux x64 to Linux aarch64, and the "special cross-compilation magic" is taken care of using the toolchain file, so no special flags need to be passed to configure via build_linux.sh.
I tried to disable the code in the if statement in the hope that the proper compiler provided in the toolchain file would be used, but this did not work (it resulted in using the local x64 compiler). My investigation continues.
After investigating further, I did indeed need to pass a different set of parameters to compile via build_linux.sh to get things compiling. Now it compiles, but I have some other things to get working before I can fully test it.
See comments in the changes below, there are still some things I could use some suggestions with...
if (VCPKG_TARGET_ARCHITECTURE STREQUAL "arm" OR VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64")
# Should add a check for cross-compilation below, but since the toolchain file hasn't been
# processed yet, CMAKE_CROSSCOMPILING is false. Does VCPKG have an equivalent?
if (VCPKG_CMAKE_SYSTEM_NAME STREQUAL "Linux")
find_program(PKGCONFIG pkg-config)
# Need to figure out a way to generate --cross-prefix below programmatically...
set(OPTIONS_CROSS " --enable-cross-compile --target-os=linux --arch=${VCPKG_TARGET_ARCHITECTURE} --cross-prefix=aarch64-linux-gnu- --pkg-config=${PKGCONFIG}")
else()
set(OPTIONS_CROSS " --enable-cross-compile --target-os=win32 --arch=${VCPKG_TARGET_ARCHITECTURE}")
vcpkg_find_acquire_program(GASPREPROCESSOR)
foreach(GAS_PATH ${GASPREPROCESSOR})
get_filename_component(GAS_ITEM_PATH ${GAS_PATH} DIRECTORY)
set(ENV{PATH} "$ENV{PATH};${GAS_ITEM_PATH}")
endforeach(GAS_PATH)
endif()
...
The code assumes that if the target is aarch64, then we must be cross-compiling. It works if we are cross-compiling to aarch64 from x64, but it probably won't work if you we are compiling on an ARM64 machine (it can happen!).
I'm better set up to test this, so I should know soon if I should produce a PR for this. Before I do that, I would prefer to have answers for the open questions above
- Is there any way to detect cross-compilation in vcpkg?
- Any suggestions on how to generate the --cross-prefix string programmatically in the portfile?
Have you tried specifying the cross-compiler (--cross-prefix)?
This is how I'm cross-compiling ffmpeg for aarch64
./configure \
--prefix=/opt/ffmpeg-aarch64 \
--enable-cross-compile \
--disable-doc \
--target-os=linux \
--arch=arm64 \
--cross-prefix=aarch64-linux-gnu- \
--enable-shared \
--enable-static
Thanks for posting this issue. ffmpeg:x64-linux can install succeed. x64-linux-dynamic is a community triplet, and there are no update about this issue for a long time. If there are new process or change of this issue, please reopen this issue.