參考:https://blog.cugxuan.cn/2019/11/01/Software/multi-main-func-run-in-clion/
最近開始用c++刷leetcode
發(fā)現(xiàn)在CLion中同時創(chuàng)建多個帶有main函數(shù)的cpp文件會報錯
上網(wǎng)查找了原因:https://blog.cugxuan.cn/2019/11/01/Software/multi-main-func-run-in-clion/
然后按照上面的解決方案嘗試了一下:
1. 在cmake的txt文件中添加如下內(nèi)容
# 遍歷項目根目錄下所有的 .cpp 文件
file (GLOB 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 ()
2. 最初狀態(tài)
image.png
3. 新增一個Leetcode0001.cpp文件
image.png
4. reload 一下項目
image.png
5. 編譯, 完成!
image.png