Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a C project with CLion

Tags:

c++

c

cmake

clion

since CLion has released a month ago there aren't many documents about it. So I'm confused about how to create a c project with CLion, when I want to create a new project I just asks the name of the project and creates a default main.cpp and CMakeLists.txt file which refers to main.cpp file. Well I can rename the file main.cpp to -> main.c and edit CMakeLists.txt manually but there are a few things in .txt file too, so I need some help over here.

Default CMakeLists.txt file;

cmake_minimum_required(VERSION 2.8.4) project(example)  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")  set(SOURCE_FILES main.cpp) add_executable(dbsg ${SOURCE_FILES}) 

Note: The problem might have an easier solution like create a C project instead of C++ project but I cannot see, so I have to let people who read this about the problem might have an easier solution then editing manually, thanks.

like image 942
fx773d Avatar asked Oct 03 '14 10:10

fx773d


People also ask

Can you use CLion for C?

A cross-platform IDE for C and C++ CLion takes a lot of the toil out of C++, allowing me to concentrate on the interesting part: problem solving.


2 Answers

From the CMake file you provided, you can simply delete the CMAKE_CXX_FLAGS line, or perhaps replace it with a C one like this:

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror") 

The rest of it should be fine, apart from renaming main.cpp to main.c as you said.

like image 162
John Zwinck Avatar answered Sep 21 '22 19:09

John Zwinck


Starting with version 2016.3.2 you can choose language (C or C++) and project type (Executable or Library) when creating a new project.

(Though this was in CodeBlocks for example for as long as I remember)) And I still never figured out whether I can create my own "project". Well IMHO CLion clearly sucks in this way if compared to CodeBlocks where I CAN WRITE MY SCRIPT FOR ALMOST EVERYTHING and customize the IDE this way((()

screenshot 1screenshot 2
screenshot 3

https://blog.jetbrains.com/clion/2016/12/clion-2016-3-2-eap/#prj_templates

PS: a screenshot on how to leave a bugreport at https://youtrack.jetbrains.com/issues/CPP
create_issue button

like image 24
Rules Avatar answered Sep 21 '22 19:09

Rules