描述:
使用CLion创建新项目,以及源文件(.c),出现提示:This file does not belong to any project target, code insight features might not work properly.

且代码编译运行出现错误
collect2.exe: error: ld returned 1 exit status mingw32-make.exe[3]: *** [项目名.exe] Error 1 mingw32-make.exe[2]: *** [CMakeFiles/项目名.dir/all] Error 2 mingw32-make.exe[1]: *** [CMakeFiles/项目名.dir/rule] Error 2 mingw32-make.exe: *** [test_030902] Error 2

解决:
经与其他项目对比发现,问题出现在CMakeLists.txt文件的add_executable上

解决方案:
手动追加源文件名至该位置
add_executable(test_030902 main.c test001.c)
并reload changes

或者创建源文件时勾选Add to targets

勾选后效果:

本文介绍了解决CLion中新建项目及源文件时遇到的问题,包括提示文件不属于任何目标及代码洞察功能可能无法正常工作的情况。通过调整CMakeLists.txt文件中的add_executable指令并重新加载更改,可以成功解决编译和运行错误。
14万+

被折叠的 条评论
为什么被折叠?



