我正在尝试为Android构建和使用ffmpeg。我的Andoid Studio版本是2.2.2,ffmpeg是3.2。关于如何导入重建库的Android文档,我认为我得到了正确的设置,但一直收到此错误
ninja: error: 'avcodec-NOTFOUND', needed by '../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/...
这是设置
add_library( avcodec SHARED IMPORTED )
add_library( avdevice SHARED IMPORTED )
add_library( avfilter SHARED IMPORTED )
add_library( avformat SHARED IMPORTED )
add_library( avutil SHARED IMPORTED )
add_library( swscale SHARED IMPORTED )
set_target_properties( avcodec
PROPERTIES FFMPEG_LIB_IMPORTED_LOCATION
libs/ffmpeg/${ANDROID_ABI}/lib/libavcodec.so
)
set_target_properties( avdevice
PROPERTIES FFMPEG_LIB_IMPORTED_LOCATION
libs/ffmpeg/${ANDROID_ABI}/lib/libavdevice.so
)
set_target_properties( avfilter
PROPERTIES FFMPEG_LIB_IMPORTED_LOCATION
libs/ffmpeg/${ANDROID_ABI}/lib/libavfilter.so
)
set_target_properties( avformat
PROPERTIES FFMPEG_LIB_IMPORTED_LOCATION
libs/ffmpeg/${ANDROID_ABI}/lib/libavformat.so
)
set_target_properties( avutil
PROPERTIES FFMPEG_LIB_IMPORTED_LOCATION
libs/ffmpeg/${ANDROID_ABI}/lib/libavutil.so
)
set_target_properties( swscale
PROPERTIES FFMPEG_LIB_IMPORTED_LOCATION
libs/ffmpeg/${ANDROID_ABI}/lib/libswscale.so
)
# Specifies a path to native header files.
include_directories(
libs/ffmpeg/${ANDROID_ABI}/include
)
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
avcodec avdevice avfilter avformat avutil swscale
${log-lib}
)
如果我指定了完整的库名libavcodec.so ......,那么错误就会消失。
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
libavcodec.so libavdevice.so libavfilter.so libavformat.so libavutil.so libswscale.so
${log-lib}
)
我想知道是否有人遇到类似问题或者知道为什么编译会这样做。
答案 0 :(得分:1)
基于Tsyvarev的输入,我在这里编译和链接的内容。
pandoc: Could not find data file /usr/local/Cellar/pandoc/1.18/share/x86_64-osx-ghc-8.0.1/pandoc-1.18/data/templates/mytemplate.latex
请注意以下重要区别:
set_target_properties中的路径必须是绝对路径。这是使用" ../../../../" libs目录下的四个级别;但是,对于include_directory中的头文件路径,它需要是相对的。我使用绝对路径,无法找到包含文件。顺便说一句,我删除了&fffmpeg'文件夹中。
add_library( avcodec SHARED IMPORTED )
add_library( avdevice SHARED IMPORTED )
add_library( avfilter SHARED IMPORTED )
add_library( avformat SHARED IMPORTED )
add_library( avutil SHARED IMPORTED )
add_library( swscale SHARED IMPORTED )
set_target_properties( avcodec
PROPERTIES IMPORTED_LOCATION
../../../../libs/${ANDROID_ABI}/lib/libavcodec.so
)
set_target_properties( avdevice
PROPERTIES IMPORTED_LOCATION
../../../../libs/${ANDROID_ABI}/lib/libavdevice.so
)
set_target_properties( avfilter
PROPERTIES IMPORTED_LOCATION
../../../..//libs/${ANDROID_ABI}/lib/libavfilter.so
)
set_target_properties( avformat
PROPERTIES IMPORTED_LOCATION
../../../../libs/${ANDROID_ABI}/lib/libavformat.so
)
set_target_properties( avutil
PROPERTIES IMPORTED_LOCATION
../../../../libs/${ANDROID_ABI}/lib/libavutil.so
)
set_target_properties( swscale
PROPERTIES IMPORTED_LOCATION
../../../../libs/${ANDROID_ABI}/lib/libswscale.so
)
# Specifies a path to native header files.
include_directories(
libs/${ANDROID_ABI}/include
)
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
avcodec avdevice avfilter avformat avutil swscale
${log-lib}
)
中的导入位置属性必须为 set_target_properties
。