CLion不解析来自外部库的标头 [英] CLion doesn't resolve headers from external library
问题描述
您好!
前一段时间,我使用XCode在C ++ 1x中创建了一个大头文件库。库的当前布局是()( ls -R sponf
)的部分输出
sponf / sponf:
ancestors sponf.h sponf_utilities.h
类别sponf_children.h实用程序
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:
distribution histogram.h随机模拟
米数字系列空间
sponf / sponf / children / distribution:
arcsine_der.h exponential.h
box_muller.h uniform.h
sponf / sponf / children / meters:
accumulator.h timer.h
#...'children'的其他子目录...
sponf / sponf / utilities:
common_math.h limits.h string_const.h
# ...其他目录...
我想将此项目移植到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;
}
程序编译并运行正常。但是,CLion不能识别空格
命名空间(在其中一个子文件中声明),也不识别 simulations
命名空间;它们都标记为红色,我无法检查其内容,也不能通过⌘ - 点击等导航到其定义...
图书馆的相关部分
查看sponf.h
我们找到
#ifndef sponf_h
#define sponf_h
/ *下面的类被导出* /
#pragma GCC可见性推动(默认)
//包括一些标准库文件
// ...
#include< Eigen / Eigen>
#includesponf_macros.h
#includesponf_utilities.h
#includesponf_children.h
# pragma GCC visibility pop
#endif
而在sponf_children.h
(位于顶层,sponf.h
旁边),我们找到
#ifndef sponf_locp_sponf_children_h
#define sponf_locp_sponf_children_h
命名空间sponf {
包括一些孩子
// ...
#includechildren / spaces / euclidean_free_space.h
#includechildren / simulations / random_walk.h
//包括剩余的子项
// ...
}
#endif
每个子头将包括其相应的祖先或类别标题(其定义子本身的超类)。
CLion的反应
尽管自动完成预测能够轻松找到所有的子目录和标题, include the directives in this last file get marked red and ⌘ - 点击任何一个会导致弹出消息
编辑器右边的功能区会出现许多错误,例如
$>
< b $ b
','或)预期
)预期
期望的类型
缺少
p>
对于每个include语句都不一样(每个都会生成从2到所有这些错误)。 p>
另一方面,CLion完全能够找到所有 Eigen
头部,它们具有几乎相同的结构! / p>
我已将两个库放在 / opt / local / include
中,并更改了 CMakeLists.txt
project(sponf)
$ b b
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工具链的第一个方法,所以任何类型的信息都将非常感谢!
对不起,很长的问题,
这里我在windows中使用cigwin64。我想在我的项目中使用Eigen库。
Eigen库位于/ usr / include / eigen中,然后编辑CMakeLists.txt并添加
include_directories usr / include / eigen)
现在CLion可以找到特征库中的所有源文件。也许这也是你想要的。
Hello!
Some time ago I started a big header library in C++1x using XCode. The current layout of the library is () something like (partial output from 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 ...
I wanted to port this project to CLion, which seems a really good IDE (based on the similar AndroidStudio IDE) but I'm getting some troubles.
Small test program
I tried this small program as a test:
#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;
}
The program compiles and runs fine. However, CLion does not recognize the spaces
namespace (declared in one of the children files), nor the simulations
namespace; they are both marked red and I cannot inspect their content, nor navigate to their definitions by ⌘-clicking, etc. etc...
Relevant parts of the library
Looking in "sponf.h"
we find
#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
while in "sponf_children.h"
(which is located at the top level, next to "sponf.h"
) we find
#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
Each "child" header will then include its corresponding "ancestor" or "category" header (which defines the superclass of the "child" itself).
The reaction of CLion
Despite the autocompletition prediction, which easily finds all the subdirectories and the headers, all the include directives in this last file get marked red and ⌘-clicking on any of them leads to a popup message
Cannot find declaration to go to
while the right ribbon of the editor signal many errors like
',' or ) expected
) expected
Declarator expected
Expecting type
Missing ;
Unexpected symbol
which are not the same for each include statement (each generates from 2 to all of these errors).
On the other hand, CLion is perfectly able to find all Eigen
headers, which have pretty much the same structure!
I have put both libs in /opt/local/include
and changed CMakeLists.txt
accordingly
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})
Why can't CLion properly parse the project structure? XCode, after having included /opt/local/include/sponf
and /opt/local/include/eigen3
in the HEADER_SEARCH_PATHS
env. variable of the project, is able to find any header while compiling the same exact program.
Is there anything else I need to know? Am I doing it wrong or is it that CLion isn't that mature yet and this is just a sorry bug? This is my first approach to the CLion and the CMake toolchain, so any kind of information about it will be greatly appreciated!
Sorry for the very long question, I didn't manage to shrink it further... Thanks in advance guys, see you soon!
Here what I did in windows using cigwin64. I wanted to use Eigen library include in my project. Eigen library is places in /usr/include/eigen then edited CMakeLists.txt and add
include_directories("/usr/include/eigen")
into it. Now CLion can find all source files in eigen lib. May be this what you wanted too.
这篇关于CLion不解析来自外部库的标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!