gpt4 book ai didi

Android Studio CMakeLists错误: undefined reference to

转载 作者:行者123 更新时间:2023-11-30 16:27:09 25 4
gpt4 key购买 nike

我有这个项目

enter image description here

我正在尝试使用 CMakeLists 构建 C 的源代码:

# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
rtmp-jni

# Sets the library as a shared library.
SHARED

# Provides a relative path to your source file(s).
${CMAKE_SOURCE_DIR}/src/main/cpp/rtmp-jni.c)

include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../jnisource"
"${CMAKE_CURRENT_SOURCE_DIR}/../jnisource/includes"
"${CMAKE_CURRENT_SOURCE_DIR}/../jnisource/includes/openssl"
"${CMAKE_CURRENT_SOURCE_DIR}/../jnisource/librtmp")

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
log-lib

# Specifies the name of the NDK library that
# you want CMake to locate.
log )

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
rtmp-jni

# Links the target library to the log library
# included in the NDK.
${log-lib} )

当我构建 APK 时,出现此错误:

Build command failed.
Error while executing process /Users/kevinabrioux/android-sdks/cmake/3.6.4111459/bin/cmake with arguments {--build /Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/.externalNativeBuild/cmake/debug/armeabi-v7a --target rtmp-jni}
[1/1] Linking C shared library ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/librtmp-jni.so
FAILED: : && /Users/kevinabrioux/android-sdks/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang --target=armv7-none-linux-androideabi --gcc-toolchain=/Users/kevinabrioux/android-sdks/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64 --sysroot=/Users/kevinabrioux/android-sdks/ndk-bundle/sysroot -fPIC -isystem /Users/kevinabrioux/android-sdks/ndk-bundle/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a --sysroot /Users/kevinabrioux/android-sdks/ndk-bundle/platforms/android-21/arch-arm -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,librtmp-jni.so -o ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/librtmp-jni.so CMakeFiles/rtmp-jni.dir/src/main/cpp/rtmp-jni.c.o -llog -lm && :
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:14: error: undefined reference to 'RTMP_Alloc'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:20: error: undefined reference to 'RTMP_Init'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:21: error: undefined reference to 'RTMP_SetupURL'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:26: error: undefined reference to 'RTMP_Connect'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:26: error: undefined reference to 'RTMP_ConnectStream'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:35: error: undefined reference to 'RTMP_Close'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:36: error: undefined reference to 'RTMP_Free'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:54: error: undefined reference to 'RTMP_Read'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:75: error: undefined reference to 'RTMP_Pause'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:84: error: undefined reference to 'RTMP_IsConnected'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:93: error: undefined reference to 'RTMP_IsTimedout'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:99: error: undefined reference to 'RTMP_Close'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:100: error: undefined reference to 'RTMP_Free'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

我该怎么做才能让我的项目找到这些对象的引用?

最佳答案

您的target_link_libraries必须包含librtmp。您不需要将其构建为项目的一部分。使用此库附带的 make 文件制作一次,并将其引用为 IMPORTED 就完全可以了,例如

add_library(shared-lib SHARED IMPORTED)
set_target_properties(shared-lib PROPERTIES IMPORTED_LOCATION
${CMAKE_CURRENT_SOURCE_DIR}/../jnisource/librtmp/lib/${ANDROID_ABI}/librtmp.so)

关于Android Studio CMakeLists错误: undefined reference to,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52830744/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com