赞
踩
报错信息 :
Build command failed. Error while executing process Y:\001_DevelopTools\002_Android_SDK\cmake\3.6.4111459\bin\cmake.exe with arguments {--build Y:\002_WorkSpace\001_AS\RTMP_Pusher\app\.externalNativeBuild\cmake\debug\armeabi-v7a --target native-lib} [1/9] Building C object librtmp/CMakeFiles/rtmp.dir/parseurl.c.o [2/9] Building C object librtmp/CMakeFiles/rtmp.dir/amf.c.o [3/9] Building C object librtmp/CMakeFiles/rtmp.dir/hashswf.c.o [4/9] Building C object librtmp/CMakeFiles/rtmp.dir/rtmp.c.o [5/9] Building C object librtmp/CMakeFiles/rtmp.dir/log.c.o In file included from Y:\002_WorkSpace\001_AS\RTMP_Pusher\app\src\main\cpp\librtmp\amf.c:33: Y:\002_WorkSpace\001_AS\RTMP_Pusher\app\src\main\cpp\librtmp/bytes.h:74:2: warning: "Float word order not defined, assuming the same as byte order!" [-W#warnings] #warning "Float word order not defined, assuming the same as byte order!" ^ 1 warning generated. [6/9] Linking C static library librtmp\librtmp.a [7/9] Building CXX object CMakeFiles/native-lib.dir/VedioChannel.cpp.o [8/9] Building CXX object CMakeFiles/native-lib.dir/native-lib.cpp.o clang++: warning: argument unused during compilation: '-LY:/002_WorkSpace/001_AS/RTMP_Pusher/app/src/main/cpp/libs/armeabi-v7a' [-Wunused-command-line-argument] clang++: warning: argument unused during compilation: '-LY:/002_WorkSpace/001_AS/RTMP_Pusher/app/src/main/cpp/libs/armeabi-v7a' [-Wunused-command-line-argument] [9/9] Linking CXX shared library Y:\002_WorkSpace\001_AS\RTMP_Pusher\app\build\intermediates\cmake\debug\obj\armeabi-v7a\libnative-lib.so FAILED: cmd.exe /C "cd . && Y:\001_DevelopTools\002_Android_SDK\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi21 --gcc-toolchain=Y:/001_DevelopTools/002_Android_SDK/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=Y:/001_DevelopTools/002_Android_SDK/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -LY:/002_WorkSpace/001_AS/RTMP_Pusher/app/src/main/cpp/libs/armeabi-v7a -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -shared -Wl,-soname,libnative-lib.so -o Y:\002_WorkSpace\001_AS\RTMP_Pusher\app\build\intermediates\cmake\debug\obj\armeabi-v7a\libnative-lib.so CMakeFiles/native-lib.dir/native-lib.cpp.o CMakeFiles/native-lib.dir/VedioChannel.cpp.o librtmp/librtmp.a -llog -latomic -lm && cd ." Y:\002_WorkSpace\001_AS\RTMP_Pusher\app\src\main\cpp/VedioChannel.cpp:23: error: undefined reference to 'x264_picture_clean' Y:\002_WorkSpace\001_AS\RTMP_Pusher\app\src\main\cpp/VedioChannel.cpp:79: error: undefined reference to 'x264_param_default_preset' Y:\002_WorkSpace\001_AS\RTMP_Pusher\app\src\main\cpp/VedioChannel.cpp:169: error: undefined reference to 'x264_picture_clean' Y:\002_WorkSpace\001_AS\RTMP_Pusher\app\src\main\cpp/VedioChannel.cpp:177: error: undefined reference to 'x264_picture_alloc' Y:\002_WorkSpace\001_AS\RTMP_Pusher\app\src\main\cpp/VedioChannel.cpp:182: error: undefined reference to 'x264_encoder_close' Y:\002_WorkSpace\001_AS\RTMP_Pusher\app\src\main\cpp/VedioChannel.cpp:186: error: undefined reference to 'x264_encoder_open_157' Y:\002_WorkSpace\001_AS\RTMP_Pusher\app\src\main\cpp/VedioChannel.cpp:248: error: undefined reference to 'x264_encoder_encode' clang++: error: linker command failed with exit code 1 (use -v to see invocation) ninja: build stopped: subcommand failed.
CMakeList.txt 构建脚本如下 : 跟着该构建脚本 , 逐步向下排查 ;
cmake_minimum_required(VERSION 3.4.1) # 链接 src/main/cpp/librtmp 目录下的构建脚本 add_subdirectory(librtmp) add_library( # 函数库名称 native-lib # 动态库类型 SHARED # 源文件 native-lib.cpp VedioChannel.cpp) find_library( # 日志库 log-lib log ) # 设置头文件搜索路径 include_directories(include) # 通过设置编译选项, 设置函数库的搜索路径 # 此处的 ANDROID_ABI 是在 # build.gradle android->defaultConfig->externalNativeBuild->cmake # 下的 abiFilters 中设置 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}") target_link_libraries( # 链接动态库 native-lib # 编译的 rtmp 静态库 rtmp ${log-lib} )
NDK 代码编译时 , 执行了 9 9 9 个步骤 , 第 1 ~ 6 步骤 :
开始构建时 , 指定第一行编译脚本内容 , add_subdirectory(librtmp) , 编译 librtmp 目录下的 CMakeList.txt 内容 ;
# 链接 src/main/cpp/librtmp 目录下的构建脚本
add_subdirectory(librtmp)
编译 RTMP 源代码 , 该步骤执行下面的构建脚本 , 编译 librtmp.so 库 , 对应了如下脚本内容 ;
cmake_minimum_required(VERSION 3.4.1) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNO_CRYPTO") add_library( # 编译的库的名称是 rtmp rtmp # 编译的 rtmp 库是静态库 STATIC # rtmp 库的源文件 amf.c hashswf.c log.c parseurl.c rtmp.c )
第 7 , 8 7 , 8 7,8 步 , 编译 VedioChannel.cpp 源码 , 编译 native-lib.cpp 源码 , 对应编译 libnative-lib.so 函数库 ;
add_library( # 函数库名称
native-lib
# 动态库类型
SHARED
# 源文件
native-lib.cpp
VedioChannel.cpp)
第 9 9 9 步 , 链接函数库 , 在这一步链接出错 , 没有找到 x264 开源库中的函数 ;
x264 开源库编译过程 : x264 开源库的头文件放在 include 目录中 , 交叉编译的函数库放在 libs/armeabi-v7a 目录中 ;
# 设置头文件搜索路径
include_directories(include)
# 通过设置编译选项, 设置函数库的搜索路径
# 此处的 ANDROID_ABI 是在
# build.gradle android->defaultConfig->externalNativeBuild->cmake
# 下的 abiFilters 中设置
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}")
x264 开源库肯定是编译通过了 , 在链接的时候 , x264 没有链接到 native-lib 中 , 导致无法访问 x264 开源库中的函数 ;
target_link_libraries( # 链接动态库
native-lib
# 编译的 rtmp 静态库
rtmp
${log-lib} )
修改方法 : 在链接库的时候 , 将 x264 库添加上去 ;
target_link_libraries( # 链接动态库
native-lib
# 编译的 rtmp 静态库
rtmp
# 预编译的 x264 静态库
x264
${log-lib} )
最终修改后的构建脚本 ( 正确构建脚本 ) :
cmake_minimum_required(VERSION 3.4.1) # 链接 src/main/cpp/librtmp 目录下的构建脚本 add_subdirectory(librtmp) add_library( # 函数库名称 native-lib # 动态库类型 SHARED # 源文件 native-lib.cpp VedioChannel.cpp) find_library( # 日志库 log-lib log ) # 设置头文件搜索路径 include_directories(include) # 通过设置编译选项, 设置函数库的搜索路径 # 此处的 ANDROID_ABI 是在 # build.gradle android->defaultConfig->externalNativeBuild->cmake # 下的 abiFilters 中设置 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}") target_link_libraries( # 链接动态库 native-lib # 编译的 rtmp 静态库 rtmp # 预编译的 x264 静态库 x264 ${log-lib} )
错误总结 : 遇到 Linking CXX shared library 步骤失败 , 并提示 error: undefined reference to 无法找到函数 , 是链接步骤出错 , 修改 CMakeList.txt 中的 target_link_libraries 链接参数 ;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。