在CLion中,仅标头库:文件“不属于任何项目目标,代码洞察功能可能无法正常工作". [英] In CLion, header only library: file "does not belong to any project target, code insight features might not work properly"

查看:2932
本文介绍了在CLion中,仅标头库:文件“不属于任何项目目标,代码洞察功能可能无法正常工作".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用cmake命令设置了仅标头的库项目:

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

add_library(my_library INTERFACE)

我还添加了

target_sources(my_library INTERFACE ${MY_LIRBARY_HEADER_FILES})

但是当我打开源文件时,得到警告:

but when I open a source file, I get the warning:

此文件不属于任何项目目标,代码洞察功能可能无法正常工作

This file does not belong to any project target, code insight features might not work properly

我在代码完成之类的事情上失去了很多功能.

and I lose a lot of the functionality on things like code completion.

什么是正确的设置方式,以便CLion在仅标头的库中提供其通常的功能?

What is the proper way to set this up so CLion provides its usual functionality on a header-only library?

推荐答案

背景很少

我遇到了同样的问题,尽管该项目不是仅标头,但是即使CMake文件将该文件夹明确标记为include_directory,从inc文件夹打开的文件仍引发上述警告.

Little background

I was having the same problem, albeit the project was not header-only, nevertheless, the open files from inc folder were throwing the aforementioned warning, even though the CMake file clearly marked that folder to be include_directory.

include_directories("${PROJECT_SOURCE_DIR}/inc/")
add_subdirectory(src)
add_executable(${EXECUTABLE_NAME} main.cpp ${SOURCE})

由于这是一个完全有效的CMake文件,并且将包含文件添加到源文件中并不是习惯做法,所以我不想修改CMake文件.

Since this is a perfectly valid CMake file and adding the include files to source files is not idiomatic, I did not want to amend the CMake file.

如官方 JetBrains论坛所述,CMake文件确实有效,并且由于CLion无法正确索引头文件而显示警告.建议从链接中提取的解决方法是右键单击该文件夹,然后单击Mark directory as | Mark directory as. Library Files/Project Sources and Headers .

As described on the official JetBrains Forum, the CMake file is indeed valid and the warning is shown because of the inability of CLion to properly index header files. The suggested workaround extracted from the link is to right-click the folder and Mark directory as | Library Files/Project Sources and Headers.

因此,此标头不包含在可执行文件中,CLion会通知您某些代码洞察功能可能无法正常工作.解决方法是,您可以使用将目录标记为"库文件/项目源和文件夹标题.

So, this header isn't includes in executables and CLion notifies you that some code insight features might not work properly. As workaround you can use "Mark directory as" Library Files/Project Source and Headers for folder.

这篇关于在CLion中,仅标头库:文件“不属于任何项目目标,代码洞察功能可能无法正常工作".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆