clion中cpp文件显示This file does not belong to any project ,code insight features might not work解决方案

Posted 牛哄哄的柯南

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了clion中cpp文件显示This file does not belong to any project ,code insight features might not work解决方案相关的知识,希望对你有一定的参考价值。

问题

cpp文件上方出现
This file does not belong to any project ,code insight features might not work properly,并且main函数无法运行

解决方案

第一步:修改下CMakeLists.txt文件

为了以后方便,我们先修改下CMakeLists.txt文件

CMakeLists.txt:

# 遍历项目根目录下所有的 .cpp 文件
file (GLOB_RECURSE files *.cpp)
foreach (file $files)
    string(REGEX REPLACE ".+/(.+)\\\\..*" "\\\\1" exe $file)
    add_executable ($exe $file)
    message (\\ \\ \\ \\ --\\ src/$exe.cpp\\ will\\ be\\ compiled\\ to\\ bin/$exe)
endforeach ()

这样以后就不用再修改CMakeLists.txt这个文件了。

第二步:重新加载下项目

加载完成后main函数就可以执行了,及时cpp文件上方还有那句话也不影响。

以上就是clion中cpp文件显示This file does not belong to any project ,code insight features might not work【解决方案】的全部内容

版权声明:
原创博主:牛哄哄的柯南
博主原文链接:https://keafmd.blog.csdn.net/

看完如果对你有帮助,感谢点击下面的一键三连支持!
[哈哈][抱拳]


加油!

共同努力!

Keafmd

都看到这里了,下面的内容你懂得,让我们共同进步!

以上是关于clion中cpp文件显示This file does not belong to any project ,code insight features might not work解决方案的主要内容,如果未能解决你的问题,请参考以下文章

CLin 和 IDEA创建文件时自动添加作者和时间信息 + 多个.cpp文件在CLion下运行问题

# Clion中编译多个cpp(实现单文件编译)

如何使 CLion 在 .cpp 文件中插入生成的代码....

Clion切换主代码文件运行

CMake File API“找不到回复目录”

如何用clion写head file