CLion中运行多个main()函数
修改CMakeLists.txt内容
cmake_minimum_required(VERSION 3.23)
project(test)
set(CMAKE_CXX_STANDARD 14)
#上面三行无需改动
#递归遍历所有的cpp文件
file (GLOB_RECURSE files *.cpp)
#将所有的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 ()
新建.cpp文件

在项目处右击,选择 Reload CMake Project


浙公网安备 33010602011771号