Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用CMake创建iOS静态库时出错_Ios_Cmake_Static Libraries - Fatal编程技术网

使用CMake创建iOS静态库时出错

使用CMake创建iOS静态库时出错,ios,cmake,static-libraries,Ios,Cmake,Static Libraries,我正试图用CMake创建一个静态的项目库,用于iOS项目 我在这里创建了一个示例项目: 构建json11目标时工作正常,但json11_测试目标返回以下错误: === BUILD TARGET json11_test OF PROJECT example_all WITH CONFIGURATION Debug === Check dependencies target specifies product type 'com.apple.product-type.tool', but ther

我正试图用CMake创建一个静态的项目库,用于iOS项目

我在这里创建了一个示例项目:

构建json11目标时工作正常,但json11_测试目标返回以下错误:

=== BUILD TARGET json11_test OF PROJECT example_all WITH CONFIGURATION Debug ===

Check dependencies
target specifies product type 'com.apple.product-type.tool', but there's no such product type for the 'iphoneos' platform

** BUILD FAILED **


The following build commands failed:
    Check dependencies
(1 failure)
最初的json11是这样的:

经过一些测试,我修改了,它的工作,但我试图找出什么是错误的

cmake_minimum_required(VERSION 3.2)
project(json11 VERSION 1.0.0 LANGUAGES CXX)

enable_testing()

add_library(json11 json11.cpp)
target_include_directories(json11 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_options(json11
  PUBLIC -std=c++11
  PRIVATE -fno-rtti -fno-exceptions -Wall -Wextra -Werror)
configure_file("json11.pc.in" "json11.pc" @ONLY)

# Commented this two lines
# add_executable(json11_test test.cpp)
# target_link_libraries(json11_test json11)

install(TARGETS json11 DESTINATION lib)
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/json11.hpp" DESTINATION include)
install(FILES "${CMAKE_BINARY_DIR}/json11.pc" DESTINATION lib/pkgconfig)
不确定问题是否存在于CMake配置、或任何其他方面

谢谢你的帮助

编辑

我没有找到解决方案,而是找到了一种变通方法,使测试成为可选的


问题在于库附带的测试目标。在C和C++中,通常有一个专用的命令行可执行文件,运行一个测试套件。在OSX上,有一种称为命令行工具的目标类型。Xcode使用反向DNS标识符引用目标类型,在本例中为
com.apple.product type.tool
。在iOS上,您没有命令行工具的目标类型,因为没有可以运行可执行文件的公共命令行


也就是说,您自己已经找到了解决方案:如果要为iOS构建,请在CMake中为该库停用测试目标生成。

问题在于库附带的测试目标。在C和C++中,通常有一个专用的命令行可执行文件,运行一个测试套件。在OSX上,有一种称为命令行工具的目标类型。Xcode使用反向DNS标识符引用目标类型,在本例中为
com.apple.product type.tool
。在iOS上,您没有命令行工具的目标类型,因为没有可以运行可执行文件的公共命令行


话虽如此,您自己已经找到了解决方案:如果您想为iOS构建,请在CMake中为该库停用测试目标生成。

我找到了解决方案,但我想知道原因是什么。ThanksI找到了解决办法,但我想知道原因是什么。谢谢
cmake_minimum_required(VERSION 3.2)
project(json11 VERSION 1.0.0 LANGUAGES CXX)

enable_testing()

add_library(json11 json11.cpp)
target_include_directories(json11 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_options(json11
  PUBLIC -std=c++11
  PRIVATE -fno-rtti -fno-exceptions -Wall -Wextra -Werror)
configure_file("json11.pc.in" "json11.pc" @ONLY)

# Commented this two lines
# add_executable(json11_test test.cpp)
# target_link_libraries(json11_test json11)

install(TARGETS json11 DESTINATION lib)
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/json11.hpp" DESTINATION include)
install(FILES "${CMAKE_BINARY_DIR}/json11.pc" DESTINATION lib/pkgconfig)