前段时间我使用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工具链的第一种方法,所以任何关于它的信息都将非常感谢!
对不起,很长一段时间的问题,我没有设法进一步缩小它...先谢谢你们,很快见到你们!