11

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!

4
  • 1
    Keep in mind that CLion is still in the EAP stage. It might be that there's a solution in the software's current state, but given that "the quality of EAP versions may at times be way below even usual beta standards", it might just be that this is a bug. Try reporting it to Jetbrains? Feb 11, 2015 at 8:41
  • You should consider deleting this question, as it was related to a temporary bug in a non-release version of software.
    – xaxxon
    Mar 16, 2016 at 21:02
  • @xaxxon The question has been flagged for moderator attention since I can't delete answered questions myself. Thanks for the input!
    – gianluca
    Mar 17, 2016 at 15:56
  • File->Reload CMake project did it for me.
    – Luis
    Jun 26, 2016 at 17:31

2 Answers 2

11

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.

3
  • Yes, that's it. The issue was probably the one alex described in his comment. He suggested that this issue could simply be related to the actual development stage of CLion. I downloaded the latest version and the problem was no longer there.
    – gianluca
    Apr 21, 2015 at 20:35
  • i added include_directories, but it didn't work. I need to add external header directory to project setting.
    – Eric
    Aug 14, 2015 at 10:56
  • 5
    What do you mean external header directory ?
    – GPrathap
    Aug 14, 2015 at 22:10
0

Downgrade to Clion 2016.1.4 fixes the problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.