我正在按照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}")
答案 0 :(得分:1)
我在这一行中注意到这一点:
target_link_libraries(${target_name} "${firebase_libs}")
未定义变量target_name
,至少在您提供的CMake代码中未定义。您将需要在此处替换您的目标的名称,而不是Firebase示例中使用的通用变量名称。尝试以下方法:
target_link_libraries(native-lib "${firebase_libs}")
答案 1 :(得分:0)
这也可能是由于未首先列出您的库引起的。例如,如果您有这样的话:
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)