gpt4 book ai didi

android - 无法为不是由该项目构建的目标指定链接库

转载 作者:行者123 更新时间:2023-11-28 04:05:21 24 4
gpt4 key购买 nike

我正在关注 this在我的 android 项目中使用 C++ 添加 firebase 的教程,我使用的是 CMake 版本 3.10.2当我运行项目时,出现以下错误:

Error configuring CMake server
(C:\Users\User\AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin).
Check for working C compiler:
C:/Users/User/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
Check for working C compiler:
C:/Users/User/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
-- works Detecting C compiler ABI info Detecting C compiler ABI info - done Detecting C compile features Detecting C compile features - done
Check for working CXX compiler:
C:/Users/User/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe
Check for working CXX compiler:
C:/Users/User/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe
-- works Detecting CXX compiler ABI info Detecting CXX compiler ABI info - done Detecting CXX compile features Detecting CXX compile
features - done Found PkgConfig:
C:/ProgramData/chocolatey/bin/pkg-config.exe (found version "0.28")
CMake Error at CMakeLists.txt:52 (target_link_libraries): Cannot
specify link libraries for target "firebase_analytics;firebase_app"
which is not built by this project.


Configuring incomplete, errors occurred!

我的 CMakeLists.txt 文件:

# 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.
native-lib

# Sets the library as a shared library.
SHARED

# Provides a relative path to your source file(s).
native-lib.cpp)

# 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.
native-lib

# Links the target library to the log library
# included in the NDK.
${log-lib})
# Add Firebase libraries to the target using the function from the SDK.
add_subdirectory(${FIREBASE_CPP_SDK_DIR} bin/ EXCLUDE_FROM_ALL)


# The core Firebase library (firebase_app) is required to use any Firebase product,
# and it must always be listed last.
set(firebase_libs firebase_analytics firebase_app)
target_link_libraries(${target_name} "${firebase_libs}")

最佳答案

这也可能是由于未首先列出您的 图书馆造成的。例如,如果你有这个:

add_library( my_native_code
SHARED

# Other stuff here
)

target_link_libraries(
android)

这将失败:

Cannot specify link libraries for target "android" which is not built by this project.

您需要确保首先列出您的图书馆:

target_link_libraries(
my_native_code
android)

关于android - 无法为不是由该项目构建的目标指定链接库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58819864/

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