CLion无法解析外部库中的标头

gia*_*uca 11 c++ header-files header-only clion

前段时间我使用XCode在C++ 1x中启动了一个大的头库.库的当前布局是()类似(部分输出ls -R sponf)

sponf/sponf:
ancestors        sponf.h                sponf_utilities.h
categories       sponf_children.h       utilities
children         sponf_macros.h           

sponf/sponf/ancestors:
function.h       meter.h        set.h                    simulation.h

sponf/sponf/categories:
free_space.h     prng.h         random_distribution.h    series.h

sponf/sponf/children:
distributions    histogram.h    random                   simulations
meters           numeric        series                   spaces

sponf/sponf/children/distributions:
arcsine_der.h    exponential.h
box_muller.h     uniform.h

sponf/sponf/children/meters:
accumulator.h    timer.h

#... other subdirs of 'children' ...

sponf/sponf/utilities:
common_math.h    limits.h       string_const.h

#... other directories ...
Run Code Online (Sandbox Code Playgroud)

我想将这个项目移植到CLion,这似乎是一个非常好的IDE(基于类似的AndroidStudio IDE),但我遇到了一些麻烦.

小测试程序

我试过这个小程序作为测试:

#include <iostream>
#include <sponf/sponf.h>

using namespace std;

int main() {
    using space = sponf::spaces::euclidean_free_space<double, 3>;
    sponf::simulations::random_walk<space> rw;

    rw.step(1);

    std::cout << rw.position.value << std::endl;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

该程序编译并运行正常.但是,CLion不识别spaces名称空间(在其中一个子文件中声明),也不识别名称simulations空间; 它们都标记为红色,我无法检查它们的内容,也无法通过单击等等导航到它们的定义......

图书馆的相关部分

看着"sponf.h"我们发现

#ifndef sponf_h
#define sponf_h

/* The classes below are exported */
#pragma GCC visibility push(default)

// include some of the standard library files
// ...

#include <Eigen/Eigen>

#include "sponf_macros.h"

#include "sponf_utilities.h"
#include "sponf_children.h"

#pragma GCC visibility pop

#endif
Run Code Online (Sandbox Code Playgroud)

而在"sponf_children.h"(位于顶层,旁边"sponf.h")我们发现

#ifndef sponf_locp_sponf_children_h
#define sponf_locp_sponf_children_h

namespace sponf {

// include some of the children
// ...

#include "children/spaces/euclidean_free_space.h"
#include "children/simulations/random_walk.h"

// include remaining children
// ...

}

#endif
Run Code Online (Sandbox Code Playgroud)

然后,每个"子"标题将包括其对应的"祖先"或"类别"标题(其定义"子"本身的超类).

克里昂的反应

尽管自动完成预测很容易找到所有子目录和标题,但最后一个文件中的所有include指令都标记为红色,并且在它们中的任何一个上单击会导致弹出消息

找不到申报单

而编辑器的右边带有许多错误信号

','或)预期

)预期

声明者预期

期待类型

失踪 ;

意外的符号

每个include语句都不相同(每个包含2到所有这些错误).

另一方面,CLion完全能够找到所有Eigen标题,它们的结构几乎相同!

我已经把两个库中/opt/local/include,并改变CMakeLists.txt相应的

cmake_minimum_required(VERSION 2.8.4)
project(sponf)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")

include_directories(/opt/local/include/sponf /opt/local/include/eigen3)

set(SOURCE_FILES main.cpp)
add_executable(sponf ${SOURCE_FILES})
Run Code Online (Sandbox Code Playgroud)

为什么CLion无法正确解析项目结构?XCode中,已经包括后/opt/local/include/sponf/opt/local/include/eigen3HEADER_SEARCH_PATHSENV.项目的变量,能够在编译相同的程序时找到任何标题.

还有什么我需要知道的吗?我做错了还是CLion还不成熟,这只是一个遗憾的错误?这是我对CLion和CMake工具链的第一种方法,所以任何关于它的信息都将非常感谢!

对不起这个很长的问题,我没有设法进一步缩小它...先谢谢你们,很快见到你们!

GPr*_*hap 11

这是我在windows中使用cigwin64所做的.我想在我的项目中使用Eigen库include.特征库放在/ usr/include/eigen中,然后编辑CMakeLists.txt并添加

  include_directories("/usr/include/eigen") 
Run Code Online (Sandbox Code Playgroud)

进去.现在CLion可以在特征库中找到所有源文件.也许这就是你想要的.

  • 你是什​​么意思外部头目录? (4认同)