描述:
使用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
勾选后效果: