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

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

猜你喜欢

转载自blog.csdn.net/weixin_43883917/article/details/124385032