CLion fails to index macros


I am trying to write a Linux kernel module with CLion. This is the cmake file:

cmake_minimum_required(VERSION 3.5)



add_definitions(-imacros /home/alex/Developer/linux/include/linux/kconfig.h)

add_custom_target(labs COMMAND $(MAKE) -C ${labs_SOURCE_DIR}

add_library(dummylib ${MY_MODULE_SOURCES})

The actual building of the kernel module is done with the externally called makefile using "add_custom_target". The "dummylib" is only there so that CLion actually starts to parse the header files and gives me auto completion. With my supplied definitions it does even compile the "dummylib" successfully (look at the screenshot). It is no kernel module though, but that does not matter ;)

My problem is the error you see in the screenshot. Somehow it says that it can't resolve all the macros defined in the kernel headers. Functions, structs and plain defines ( "MODULE_SIG_STRING ") do work (as you see). I do not understand why the editor says it cannot resolve the macro but can still build it. What is more strange is that I can even jump to the declaration using STRG+B of the marked macros. Clearly something is going wrong. The macros are really defined within linux/module.h

Do you have any idea how to resolve this Situation?


Comment actions Permalink

clion parses files differently from compiler, so this problems are excepted (compiler understand something clion don't)

The rest of comment is not a fix, but a check of what clion thinks about that macro:

ensure that INCLUDE_DIRECTORIES on cmake adds that headers (for me it fails to do so).

A quick fix to see what's happening underneath is to add:

#include "/usr/lib/modules/4.5.4-1-ARCH/build/include/linux/module.h"
#include "/usr/lib/modules/4.5.4-1-ARCH/build/include/linux/moduleparam.h"

or whatever your path is.

Maybe at that point clion resolves macro correctly. Then you're fixing your file to work with your IDE (bad thing)

If not, but problem change, as happens to me:

"Error after macro substitution, Instantiating an unknown structure without a reference"

Install psiviewer

 and check what clion thinks your macro is.

Looking for MODULE_LICENSE it finds it is:

#define MODULE_LICENSE(_license) MODULE_INFO(license, _license)


#define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)


#define __MODULE_INFO(tag, name, info)

For me psiviewer says it is a Psicomment.

Seems clion has tons of parse errors like this, we must wait

Comment actions Permalink

Thank you for your response.

The includes did not change anything for me. It already had the correct includes.

What makes the thing work is switching from -std=gnu89 to -std=c89 which makes the build fail but the IDE behave somewhat correct. I also tested with PsiViewer and the result is that even though the IDE behaves differently, the PSIViewer both times says it is a define. I dumped the psi of module.h once with each -std setting. There are some differences but I do not understand all of this. I just leave this here. I also made a bug report about this: 

This is where you can find the Psi dumps (and diff them).

Comment actions Permalink

Since you provide a scce. It was easy to reply.

Without changing -std see clion don't complain if macros are used inside a function

void foo() {
MODULE_AUTHOR("bla bla");
MODULE_DESCRIPTION("bla bla bla");


Comment actions Permalink

I'm having the exact same issue as Alexander. Do you have any progress on this?

Thank you in advance.

Comment actions Permalink

I would be glad about a solution, too!

Comment actions Permalink

I will also request a solution to this.  Without _POSIX defined, I have numerous files with falsely reported undefined symbols, for example.  What a hassle.  My IDE is supposed to clarify where my problems are, not obfuscate them.

Comment actions Permalink

Hi all!

I kindly ask you to comment or upvote the issue created by Alexander: Please follow it to get updates.


Please sign in to leave a comment.