我正在尝试构建一些混合的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})
答案 0 :(得分:1)
您将C_SOURCE
变量设置为源和标头列表,但在命令link_directories
和target_link_libraries
中使用它,与链接相关,而不是编译
您可能需要将此变量的内容添加到SOURCE_FILES
。