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

前端 未结 3 1268
面向向阳花
面向向阳花 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:24

    You can add the header files to your project like this:

    set(SOURCE_FILES main.cpp MyClass1.cpp MyClass1.h MyClass2.cpp MyClass2.h)
    

    You can also set it in multiple steps like so:

    set(SOURCE_FILES main.cpp)
    set(SOURCE_FILES ${SOURCE_FILES} MyClass1.cpp MyClass1.h)
    set(SOURCE_FILES ${SOURCE_FILES} MyClass2.cpp MyClass2.h)
    

    Though as mentioned in the comments, you probably shouldn't be adding the header files to your project at all.

提交回复
热议问题