How to Create, Compile, And Run a single file in CLion

前端 未结 6 517
情话喂你
情话喂你 2021-01-31 03:07

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.

I also don\'t like how when you creat

6条回答
  •  甜味超标
    2021-01-31 03:45

    You may modify the CMakeLists.txt

    Here an example :

    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})
    

    Or use a test (garbage version) :
    add_executable(foo bar.cc)

    After that you can choose the build you want in CLion

提交回复
热议问题