如何在CLion中创建,编译和运行单个文件 [英] How to Create, Compile, And Run a single file in CLion
问题描述
我正在处理一些 c ++ 的东西,我讨厌创建一个全新的项目只是为了在文件上运行一些东西。
I am working on some c++ stuff and I hate having to create a whole new project just to run a few things on a file.
我也不喜欢如何当你创建一个项目文件已经调用 main.cpp
。
I also don't like how when you create a project a file is already called main.cpp
.
我只想做一个单一的文件与几个函数或类。创建一个整个项目并不重要。
I just want to make a single file with a few functions or classes. It's not important enough to create a whole project.
我想创建一个文件并调用它我想要的。只需创建一个我调用的文件,然后编译并运行。
I want to create a file and call it what i want. Just create a file what I call, then compile and run.
我不想处理整个 CMake
thing,只需编译一个文件。
I don't want to deal with the whole CMake
thing, just compile ONE file.
没有项目相关。谢谢。
我知道你可以在visual studio上做这个,但我正在使用 Clion
I know you can do this on visual studio, but i am working on a mac OS X using Clion
.
推荐答案
您可以修改CMakeLists.txt
You may modify the CMakeLists.txt
例如:
cmake_minimum_required(VERSION 3.3)
project(test_build)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(BUILD_1 main)
set(SOURCE_FILES_1 main.cc) //where main.cc is your first main/program
add_executable(${BUILD_1} ${SOURCE_FILES_1})
set(BUILD_2 main_2)
set(SOURCE_FILES_2 main_2.cc) //where main_2.cc is your second main/program
add_executable(${BUILD_2} ${SOURCE_FILES_2})
或使用测试(垃圾版):
add_executable(foo bar.cc)
之后,您可以在CLion
After that you can choose the build you want in CLion
这篇关于如何在CLion中创建,编译和运行单个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!