0

Here is the project structure, which tells how I included libraries in cpp directory, enter image description here

libavcodec,libavutil are subfolders from ffmpeg,

Here is CMakeList.txt

cmake_minimum_required(VERSION 3.4.1)

set(CMAKE_C_STANDARD 17)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "-D__STDC_CONSTANT_MACROS")

#project(libavcodec)
#project(libavutil)

#set_target_properties(libavcodec PROPERTIES LINKER_LANGUAGE C)

set(AVCODEC_FILES libavcodec/libavcodec.v)
set(AVUTIL_FILES libavutil/libavutil.v)
add_executable(libavcodec ${AVCODEC_FILES})
target_include_directories(libavcodec PRIVATE
        $<BUILD_INTERFACE: ${AVCODEC_FILES} >
        $<INSTALL_INTERFACE: ${AVCODEC_FILES} >
        )
#target_link_libraries(ffmpeg PRIVATE ${AVCODEC_FILES} ${AVUTIL_FILES})

And I'm getting

CMake Error: CMake can not determine linker language for target: libavcodec Failed to compute build system.

Note: FFMPEG written in C language.

Gunaseelan
  • 14,415
  • 11
  • 80
  • 128
  • "FFMPEG written in C language." - But the file [libavcodec/libavcodec.v](https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/libavcodec.v) you pass as the only source for `libavcodec` library is not a C file. This is a file for the linker, so your library has no source files. – Tsyvarev Nov 10 '19 at 18:36
  • @Tsyvarev I changed it as `set(AVCODEC_FILES libavcodec)`, still I'm getting same error. – Gunaseelan Nov 10 '19 at 18:44
  • What do you **want to achieve** actually? Do you want to build `libavcodec` library from **sources**? Then you need to specify source files (`.c` ones). If you already have `libavcodec` and want to link with it, see that question: https://stackoverflow.com/questions/8774593/cmake-link-to-external-library (if you follow the [second answer](https://stackoverflow.com/a/10550334/3440745), note on the `IMPORTED` keyword when declare the library target). – Tsyvarev Nov 10 '19 at 18:47
  • Actually I have the source code downloaded from https://www.ffmpeg.org/download.html , I want to use it my app. I don't know how. In some old posts they created .so files first, then add it into Android Studio, But according to https://developer.android.com/studio/projects/add-native-code.html I'm guessing we can add source code directly. that's what I'm trying now. – Gunaseelan Nov 10 '19 at 18:52
  • As I said, if you want to build the library from sources, you need to provide source files in `add_library` call. But as you can see, the library has **many** sources, which you need to properly choose/adjust. It would be simpler to get the library pre-built. – Tsyvarev Nov 10 '19 at 19:00
  • So you are saying we have to build the library first [like share library .so], and then import here? – Gunaseelan Nov 10 '19 at 19:03
  • https://stackoverflow.com/questions/54609484/linking-libavcodec-in-cmake-find-library-wont-work-with-any-library – rustyx Nov 10 '19 at 19:35

0 Answers0