CLion 不解析外部库中的标头
CLion doesn't resolve headers from external library
前段时间我使用 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;
}
程序编译并运行良好。但是,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
而在"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
然后,每个"子"标头将包含其相应的"祖先"或"类别"标头(定义"子"本身的超类(。
CLion的反应
尽管有自动完成预测,它很容易找到所有的子目录和头,但最后一个文件中的所有包含指令都被标记为红色,⌘ 单击其中任何一个都会导致弹出消息
找不到要转到的声明
虽然编辑器的右侧功能区表示许多错误,例如
","或"预期
( 预期
预期声明符
期待类型
失踪;
意外符号
每个 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})
为什么 CLion 无法正确解析项目结构?XCode,在将/opt/local/include/sponf
和/opt/local/include/eigen3
纳入HEADER_SEARCH_PATHS
环境之后。项目的变量,能够在编译相同的确切程序时找到任何标题。
还有什么我需要知道的吗?是我做错了,还是CLion还没有那么成熟,这只是一个令人遗憾的错误?这是我对CLion和CMake工具链的第一次接触,所以任何关于它的信息都将不胜感激!
对不起,这个问题很长,我没有设法进一步缩小它......提前感谢伙计们,很快再见!
这是我使用 cigwin64 在 Windows 中所做的。我想在我的项目中使用特征库包含。Eigen 库位于/usr/include/eigen 中,然后编辑 CMakeLists.txt并添加
include_directories("/usr/include/eigen")
进去。现在 CLion 可以在 eigen lib 中找到所有源文件。也许这也是你想要的。
到 Clion 2016.1.4 修复了问题
- 无法在 CLion 中构建 C++ 项目
- C++:如何在CLion IDE中安装Boost
- 在函数内部的声明中初始化数组,并在外部使用它
- 使外部项目可用于find_package CMake
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- 使用外部SDK工具链文件在VisualStudio上生成项目编译错误
- C++:来自外部文件的Trivia
- 从函数角度看ID到文件路径的内部与外部映射
- C++:将外部库链接到dll库
- spdlog标头仅与外部fmt一起使用.spdlog错误:'内部':不是'fmt'
- 节俭并发:未解决的外部问题
- 如何在c++中从git建立外部库
- 未解析的外部符号_MsiLocateComponentW@12.
- 如何使用对C函数和类对象的外部调用来处理C++头文件
- 将外部 C++ 库添加到 CLion 项目
- CLion 不索引任何外部包含路径
- 通过 CMake 将外部库包含在 CLion 项目中
- 如何使用CMake将外部库(boost)包含到CLion C++项目中
- CLion 不解析外部库中的标头
- CLion:通过添加源文件启用外部库的调试