gpt4 book ai didi

c++ - `/path/to/uthash/utarray.h' 需要 CMake make[2] : *** No rule to make target `HelloTest' , 。停止

转载 作者:行者123 更新时间:2023-11-28 06:08:03 24 4
gpt4 key购买 nike

我正在尝试构建一些混合的 C/C++ 代码来运行一些简单的测试代码 (HelloTest):

#include <iostream>
#include "cpp_header.h"
extern "C"
{
#include "c_header.h"
}

using namespace std;

int main(int argc, char **argv) {
cout << "Hello, World!" << endl;
return 0;
}

但是我得到了这个非常奇怪的错误:

/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/user/Library/Caches/clion10/cmake/generated/c1d0f54d/c1d0f54d/Debug --target all -- -j 2
make[2]: *** No rule to make target `/path/to/uthash/utarray.h', needed by `HelloTest'. Stop.
make[1]: *** [CMakeFiles/HelloTest.dir/all] Error 2
make: *** [all] Error 2

现在,utarray.h 是 uthash (http://troydhanson.github.io/uthash/) 的一部分,精明的读者会知道这不是 .c/cpp 丢失的问题 - utarray.h 没有。

CMake 文件看起来像这样

cmake_minimum_required(VERSION 3.2)
project(HelloTest)

# CPP stuff
find_package(CPP_PACKAGE REQUIRED)
include_directories(${CPP_PACKAGE_INCLUDE_DIR})
link_directories(${CPP_PACKGE_LIB_DIR})

# C Headers
set(C_ROOT_DIR "/path/to/c/library")
set(C_INCLUDE_DIR ${C_ROOT_DIR}/src
${C_ROOT_DIR}/ext/mtrand
${C_ROOT_DIR}/ext/uthash/src)
include_directories(${C_INCLUDE_DIR})

# C Headers & Source [we want to avoid globbing]
set(C_SOURCE ${C_ROOT_DIR}/src/bnp.c
${C_ROOT_DIR}/src/bnp.h
.
.
.
${C_ROOT_DIR}/ext/uthash/utarray.h
${C_ROOT_DIR}/ext/uthash/uthash.h
${C_ROOT_DIR}/ext/uthash/utlist.h
${C_ROOT_DIR}/ext/uthash/utstring.h)
link_directories(${C_SOURCE})

set(SOURCE_FILES main.cpp)
add_executable(HelloTest ${SOURCE_FILES})
target_link_libraries(HelloTest ${CPP_LIBRARIES} ${C_SOURCE})

最佳答案

您将 C_SOURCE 变量设置为源和 header 列表,但在与 链接相关的命令 link_directoriestarget_link_libraries 中使用它,不是编译

您可能需要将此变量的内容附加到 SOURCE_FILES

关于c++ - `/path/to/uthash/utarray.h' 需要 CMake make[2] : *** No rule to make target `HelloTest' , 。停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31976279/

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