In CLion, header only library: file “does not belong to any project target, code insight features might not work properly”

前端 未结 3 1273
面向向阳花
面向向阳花 2021-01-30 12:54

I have a header-only library project set up with the cmake command:

add_library(my_library INTERFACE)

and I also added

target_         


        
3条回答
  •  不知归路
    2021-01-30 13:22

    Clion takes information about source files from CMake build system. When you add any cpp file to sources list CMake automatically tell about header with same name. So if cpp/h names differs (or you don't have cpp file at all) you should include header manually.

    set(Sources my_lib.cpp)
    set(Headers header_of_my_lib.h)
    add_executable(superlib ${Sources} ${Headers})
    

    If you don't have any executable you can omit last line, CLion will still know about files

提交回复
热议问题