CLion code navigation with C++ doesn't work
Asked Answered
M

4

14

I've used AppCode (Intellij C++/ObjC IDE that replaces Xcode) for a while and really gotten used to being able to Ctrl+Click on any identifier to get to its definition/decleration.

Now on a new work place, I'm using CLion for a somewhat larger code base and Ctrl+Click hardly ever works. It only seem to work when the identifier is in the same file.

Is there anything I need to setup for this to work correctly? CLion seem to index the code successfully and doing text searches works fine.

Manlike answered 19/6, 2018 at 8:18 Comment(0)
S
5

You need to use import project functionality of CLion from File -> Import Project and give ok for CMakeLists.txt file automatic creation. Never mind the file is for CMake, you can build your project with other tools too, but CLion uses it for the dependencies.

Then append in the beginning of that file a line stating:

include_directories(.)

After that go to File -> Settings and there search for Keymap from the left and after that on right, right below the word "keymap" there is a selection element for taking for example Eclipse default keymapping in use and there you have at least (I tested only it) the ctrl + click functionality working like charm!!

kudos about the include_directories(.) goes to this question: CLion indexer does not resolve some includes in the project directory

Sansculotte answered 23/6, 2018 at 18:46 Comment(0)
G
1

You need to press ctrl + alt + shift + n.
And after pressing it a dialog box will appear to enter your variable/function name and click enter. Tip: Filter the result for a better experience. Filter option is present on right side of the dialog box.


To get a quick peek of function/variable definition press ctrl + q while focusing on the variable or function.

To get the detailed or full definition of function press ctrl + shift + i while focusing on the variable or function.

Gainor answered 26/6, 2018 at 22:9 Comment(0)
A
1

What helped me was to run File > New CMake Project from Sources

Until that point, Ctrl+click in CLion would go to the definitions, but wouldn't find any usages.

Albedo answered 10/11, 2020 at 12:49 Comment(0)
A
0

I just looked at one of my more complicated teaching examples with multiple header/source files where this would come up.

What I see is that ctl-click (and the red/green arrows in the gutter) does work only in the same file. But I can right-click on a method from another file and choose to go to either the declaration (in header) or definition (in cpp).

The hotkeys to do this are not ctl-click. But you can remap hotkeys in IntelliJ ides, so you may be able to come up with hotkey combinations that don't seem too awkward to you.

Aloisius answered 20/6, 2018 at 16:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.