提问人:savaresef 提问时间:1/31/2023 最后编辑:273Ksavaresef 更新时间:1/31/2023 访问量:219
ar:在 macOS 上构建 c++ 时未指定存档成员(cmake、make)
ar: no archive members specified when building c++ on macOS (cmake , make)
问:
大家好,首先非常感谢您的支持。
我有一个非常简单的项目。该项目在 Ubuntu 环境中运行良好,但在 macOS 环境中运行不正常。 结构如下
|-include
|-CMakeLists.txt
|-TSQueue
|-src
|-CMakeLists.txt
|-main.cpp
CMakeLists.txt
build
在 CMake 和 Make 之后,我收到以下错误:
[33%] Linking CXX static library libBClasses.a
ar: no archive members specified
usage: ar -d [-TLsv] archive file ...
ar -m [-TLsv] archive file ...
ar -m [-abiTLsv] position archive file ...
ar -p [-TLsv] archive [file ...]
ar -q [-cTLsv] archive file ...
ar -r [-cuTLsv] archive file ...
ar -r [-abciuTLsv] position archive file ...
ar -t [-TLsv] archive [file ...]
ar -x [-ouTLsv] archive [file ...]
make[2]: *** [include/libBClasses.a] Error 1
make[1]: *** [include/CMakeFiles/BClasses.dir/all] Error 2
make: *** [all] Error 2
层次结构顶部的 CMakeLists 为:
cmake_minimum_required(VERSION 3.6)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(THREADS_PREFER_PTHREAD_FLAG ON)
project(TSQueue)
add_subdirectory(include)
add_subdirectory(src)
include 目录中的 cmakelist 文件为:
project(basic_classes)
add_library (QClass TSQueue.hpp)
target_link_libraries(QClass pthread)
set_target_properties(QClass PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories (QClass PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(QClass ${QClass})
include_directories(${PROJECT_SOURCE_DIR}/include)
src 中的 CMakelists 是:
project(src_files)
add_executable (main_prog main.cpp)
include_directories(${PROJECT_SOURCE_DIR}/include)
target_link_libraries (main_prog LINK_PUBLIC QClass)
需要强调的一点是,在包含中,我只有一个模板化类,因此它只是一个 .hpp 类
我试图随机解决问题,但我无法真正找到解决方案的方向 非常感谢您的帮助。
我在谷歌上搜索了这个问题并使用了stackoverflow,但我想我缺乏了解问题真正本质的知识,而且在阅读建议的解决方案时很容易迷失方向。
答: 暂无答案
评论
set(sources QueueTs.hpp WordList.hpp) add_library(BClasses SHARED ${sources}) set_target_properties(BClasses PROPERTIES LINKER_LANGUAGE CXX) target_link_libraries(BClasses pthread) set_target_properties(BClasses PROPERTIES OUTPUT_NAME "BClasses") target_include_directories (BClasses PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})