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文件

image

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

image

posted @ 2022-11-26 10:15  当惜  阅读(142)  评论(0)    收藏  举报