问题 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 ...

我想将这个项目移植到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;
}

该程序编译并运行正常。但是,克里昂不承认 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

而在 "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

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

克里昂的反应

尽管自动完成预测很容易找到所有子目录和标题,但最后一个文件中的所有include指令都标记为红色, - 点击其中任何一个都会弹出一条弹出消息

找不到申报单

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

','或)预期

)预期

声明者预计

期待类型

失踪 ;

意外的符号

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

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

我把两个lib都放进去了 /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})

为什么CLion无法正确解析项目结构? XCode,包括之后 /opt/local/include/sponf 和 /opt/local/include/eigen3 在里面 HEADER_SEARCH_PATHS ENV。项目的变量,能够在编译相同的程序时找到任何标题。

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

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


4782
2018-02-11 08:20


起源

请记住,CLion仍处于EAP阶段。可能是软件当前状态有一个解决方案,但鉴于此 “EAP版本的质量有时可能低于通常的beta标准”,这可能只是一个错误。尝试向Jetbrains报告? - Alex Reinking
您应该考虑删除此问题,因为它与非发布版本的软件中的临时错误有关。 - xaxxon
@xaxxon此问题已被标记为主持人注意,因为我自己无法删除已回答的问题。感谢您的投入! - gianluca
File-> Reload CMake项目为我做了。 - Luis


答案:


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

  include_directories("/usr/include/eigen") 

进去。现在CLion可以在eigen lib中找到所有源文件。也许这就是你想要的。


10
2018-04-19 06:10



对,就是那样。问题可能是他在评论中描述的那个亚历克斯。他认为这个问题可能与CLion的实际发展阶段有关。我下载了最新版本,问题不再存在。 - gianluca
啊,那很好。 - GPrathap
我添加了include_directories,但它没有用。我需要将外部头目录添加到项目设置中。 - Eric
你是什​​么意思外部头目录? - GPrathap


降级到Clion 2016.1.4解决了这个问题


0
2018-02-09 13:05