FFmpeg - Libavcodec - unable to compile, errors on files not found, but files are there

1.7k views Asked by At

This is less about C++, and more about specific compiling avcodec and avformat as those are used inside FFmpeg. I'm trying to compile for the first time ffmpeg project code. All the linking has been resolved, and the program errors our.

I'm writing my first program - attempt at avformat libraries inside my C++ code. Linker errors on this line:

/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/sasha/CLionProjects/ffmpeg-01 --target all -- -j 12
Scanning dependencies of target docs
[  5%] Generating HTML documentation
[ 20%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/input.c.o
[ 20%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/init.c.o
[ 20%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/context.c.o
[ 30%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/vulkan.c.o
[ 30%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/monitor.c.o
[ 35%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/cocoa_init.m.o
[ 45%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/cocoa_joystick.m.o
[ 45%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/window.c.o
[ 50%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/cocoa_monitor.m.o
[ 60%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/cocoa_window.m.o
[ 60%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/cocoa_time.c.o
[ 60%] Built target docs
[ 65%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/posix_thread.c.o
[ 70%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/nsgl_context.m.o
[ 75%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/egl_context.c.o
[ 80%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/osmesa_context.c.o
[ 85%] Linking C static library libglfw3.a
[ 85%] Built target glfw
[ 95%] Building CXX object CMakeFiles/ffmpeg_01.dir/src/main.cpp.o
[ 95%] Building CXX object CMakeFiles/ffmpeg_01.dir/src/load_frame.cpp.o
[100%] Linking CXX executable ffmpeg_01
clang: error: no such file or directory: 'VideoToolbox'
clang: error: no such file or directory: 'CoreFoundation'
clang: error: no such file or directory: 'CoreMedia'
clang: error: no such file or directory: 'CoreVideo'
clang: error: no such file or directory: 'CoreServices'
clang: error: no such file or directory: 'OpenGL'
clang: error: no such file or directory: 'CoreImage'
clang: error: no such file or directory: 'AppKit'
clang: error: no such file or directory: 'Foundation'
clang: error: no such file or directory: 'CoreAudio'
clang: error: no such file or directory: 'AVFoundation'
clang: error: no such file or directory: 'CoreGraphics'
make[2]: *** [ffmpeg_01] Error 1
make[1]: *** [CMakeFiles/ffmpeg_01.dir/all] Error 2
make: *** [all] Error 2

This is the content of my *libavcodec.pc file, and it has an entry of conflicts: which lists all of the items that clang cannot find, I don't know if those are linked somehow. I found a source pointing that similar error appears if I had other forks of ffmpeg, but I do not.

prefix=/usr/local
exec_prefix=${prefix}
libdir=/usr/local/lib
includedir=/usr/local/include

Name: libavcodec
Description: FFmpeg codec library
Version: 58.108.100
Requires: libswresample >= 3.8.100, libavutil >= 56.60.100
Requires.private: 
Conflicts:
Libs: -L${libdir}  -lavcodec -liconv -lm -llzma -lz -framework AudioToolbox -L/usr/local/Cellar/x264/r3011/lib -lx264 -pthread -framework VideoToolbox -framework CoreFoundation -framework CoreMedia -framework CoreVideo -framework CoreServices
Libs.private: 
Cflags: -I${includedir}

I don't have experience in cmakefile, I can paste it here if needed. Any help is greatly appreciated, because I'm stuck for the past several days.

I have two CMakeLists:

cmake_minimum_required(VERSION 3.17)
project(ffmpeg_01)

set(CMAKE_CXX_STANDARD 14)

add_subdirectory(lib/glfw)
add_subdirectory(lib/FFmpeg)

add_definitions(-DGL_SILENCE_DEPRECIATION)

if(APPLE)
    list(APPEND EXTRA_LIBS
            "-framework OpenGL"
            )
elseif(LINUX)
    list(APPEND EXTRA_LIBS
            "-lGL -lGLU -lX11")
endif()

add_executable(ffmpeg_01 src/main.cpp src/load_frame.cpp)
target_link_libraries(ffmpeg_01 FFmpeg glfw ${EXTRA_LIBS})

and the interface for FFmpeg under FFmpeg sub directory:

cmake_minimum_required(VERSION 3.17)
project(FFMPEG)

find_package(PkgConfig REQUIRED)

pkg_check_modules(AVCODEC    REQUIRED IMPORTED_TARGET libavcodec)
pkg_check_modules(AVFORMAT   REQUIRED IMPORTED_TARGET libavformat)
pkg_check_modules(AVFILTER   REQUIRED IMPORTED_TARGET libavfilter)
pkg_check_modules(AVDEVICE   REQUIRED IMPORTED_TARGET libavdevice)
pkg_check_modules(AVUTIL     REQUIRED IMPORTED_TARGET libavutil)
pkg_check_modules(SWRESAMPLE REQUIRED IMPORTED_TARGET libswresample)
pkg_check_modules(SWSCALE    REQUIRED IMPORTED_TARGET libswscale)

add_library(FFmpeg INTERFACE IMPORTED GLOBAL)

target_link_libraries(FFmpeg INTERFACE PkgConfig::AVCODEC)
target_link_libraries(FFmpeg INTERFACE PkgConfig::AVFORMAT)
target_link_libraries(FFmpeg INTERFACE PkgConfig::AVFILTER)
target_link_libraries(FFmpeg INTERFACE PkgConfig::AVDEVICE)
target_link_libraries(FFmpeg INTERFACE PkgConfig::AVUTIL)
target_link_libraries(FFmpeg INTERFACE PkgConfig::SWRESAMPLE)
target_link_libraries(FFmpeg INTERFACE PkgConfig::SWSCALE)

I also tried adding the following block below target_link_libraries, but no difference on compilation outcome:

target_link_options(FFmpeg INTERFACE
        ${AVCODEC_LDFLAGS_OTHERS}
        ${AVFORMAT_LDFLAGS_OTHERS}
        ${AVFILTER_LDFLAGS_OTHERS}
        ${AVDEVICE_LDFLAGS_OTHERS}
        ${AVUTIL_LDFLAGS_OTHERS}
        ${SWRESAMPLE_LDFLAGS_OTHERS}
        ${SWSCALE_LDFLAGS_OTHERS}
        )
0

There are 0 answers