CMake make [2]:***没有规则来创建目标`/path/to/uthash/utarray.h&#39 ;,这是`HelloTest'所需要的.停止 [英] CMake make[2]: *** No rule to make target `/path/to/uthash/utarray.h', needed by `HelloTest'. Stop

查看:113
本文介绍了CMake make [2]:***没有规则来创建目标`/path/to/uthash/utarray.h&#39 ;,这是`HelloTest'所需要的.停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to build some mixed C/C++ code to run some simple test code (HelloTest) as such:

#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;
}

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

but I get this very strange error:

/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 没有一个.

Now, utarray.h is part of uthash (http://troydhanson.github.io/uthash/), and savvy readers will know that this is not a question of the .c/cpp missing - utarray.h doesn't have one.

CMake文件-ish看起来像这样

The CMake file -ish looks like this

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 变量设置为源列表和标头列表,但在命令 link_directories target_link_libraries ,与 linking 相关,而不是 compiling .

You set C_SOURCE variable to list of sources and headers, but use it in commands link_directories and target_link_libraries, related to linking, not a compiling.

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

Probably, you need to append content of this variable to SOURCE_FILES instead.

这篇关于CMake make [2]:***没有规则来创建目标`/path/to/uthash/utarray.h&#39 ;,这是`HelloTest&#39;所需要的.停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆