gpt4 book ai didi

c++ - Cmake 在使用目标 target_include_directories 时无法指定包含目录

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

我在我的项目中使用子模块 GitHub,现在我想使用 target_include_directories 将文件包含在我的项目类中

这是我的cmake配置

cmake_minimum_required(VERSION 3.9)
project(SpyCBlock)

set(CMAKE_CXX_STANDARD 14)

#bitcoin rpc lib
find_library(bitcoinapi 0.3 REQUIRED)

target_include_directories(rapidjson PUBLIC include/rapidjson/include)

target_include_directories(spycblockrpc PUBLIC include/spycblockrpc)

target_include_directories(btccryptography PUBLIC include/bitcoin-cryptography-library)

add_executable(

${PROJECT_NAME}

#other inclusion file cpp

#cpp-properties file include
include/cpp-properties/src/Properties.cpp
include/cpp-properties/src/PropertiesParser.cpp
include/cpp-properties/src/PropertiesUtils.cpp

#include bitcoin-cryptography-library
include/bitcoin-cryptography-library/cpp/Sha256.cpp
include/bitcoin-cryptography-library/cpp/Sha256Hash.cpp
include/bitcoin-cryptography-library/cpp/Utils.cpp

#include spycblocrpc
include/spycblockrpc/core/graph/TransactionGraph.cpp
include/spycblockrpc/core/graph/WrapperInformations.cpp
include/spycblockrpc/ConfiguratorSingleton.cpp

include/spycblockrpc/commands/DecodeScriptCommand.cpp
include/spycblockrpc/commands/DecodeRawTransaction.cpp
include/spycblockrpc/commands/HeightBlockchainCommand.cpp
include/spycblockrpc/commands/DecodeBlockAtIndexCommand.cpp

)

#bitcoin rpc lib
target_link_libraries(SpyCBlockTests bitcoinapi)
target_link_libraries(${PROJECT_NAME} bitcoinapi)

运行 CMake 时出现此错误

Starting to parse CMake project.
CMake Error at CMakeLists.txt:20 (target_include_directories):
Cannot specify include directories for target "rapidjson" which is not
built by this project.


CMake Error at CMakeLists.txt:22 (target_include_directories):
Cannot specify include directories for target "spycblockrpc" which is not
built by this project.


CMake Error at CMakeLists.txt:24 (target_include_directories):
Cannot specify include directories for target "btccryptography" which is
not built by this project.


CMake Error at CMakeLists.txt:26 (target_compile_definitions):
Cannot specify compile definitions for target "cppproperties" which is not
built by this project.

我是 C++ 和 cmake 的新手,我不明白我错了什么

最佳答案

我想添加这个问题的解决方案,按照评论中的建议,代码有两个问题:

target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/include/rapidjson/include)
  1. 目标的第一个参数必须是可执行文件的名称,因此在本例中是 SpyCBlock
  2. 第二个问题是目标声明之前的目标定义,target_include_directories(SpyCBlock ...)add_executable(${PROJECT_NAME} ...) 之前定义

一个最小的正确示例是:

add_executable(
${PROJECT_NAME}

#other inclusion file cpp

#cpp-properties file include
include/cpp-properties/src/Properties.cpp
include/cpp-properties/src/PropertiesParser.cpp
include/cpp-properties/src/PropertiesUtils.cpp

#include bitcoin-cryptography-library
include/bitcoin-cryptography-library/cpp/Sha256.cpp
include/bitcoin-cryptography-library/cpp/Sha256Hash.cpp
include/bitcoin-cryptography-library/cpp/Utils.cpp

#include spycblocrpc
include/spycblockrpc/core/graph/TransactionGraph.cpp
include/spycblockrpc/core/graph/WrapperInformations.cpp
include/spycblockrpc/ConfiguratorSingleton.cpp

include/spycblockrpc/commands/DecodeScriptCommand.cpp
include/spycblockrpc/commands/DecodeRawTransaction.cpp
include/spycblockrpc/commands/HeightBlockchainCommand.cpp
include/spycblockrpc/commands/DecodeBlockAtIndexCommand.cpp
)

target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/include/rapidjson/include)

现在我可以像这样包含库 <bitcoin-cryptography-library/Sha256.h> .

关于c++ - Cmake 在使用目标 target_include_directories 时无法指定包含目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57671273/

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