如何使用 CLion 创建 C 项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26177390/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 11:32:47  来源:igfitidea点击:

How to create a C project with CLion

c++ccmakeclion

提问by fx773d

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.

自从 CLion 一个月前发布以来,关于它的文档并不多。所以我对如何使用 CLion 创建 ac 项目感到困惑,当我想创建一个新项目时,我只是询问项目的名称并创建一个默认的 main.cpp 和 CMakeLists.txt 文件,该文件引用了 main.cpp 文件。好吧,我可以将文件 main.cpp 重命名为 -> main.c 并手动编辑 CMakeLists.txt,但 .txt 文件中也有一些内容,所以我需要一些帮助。

Default CMakeLists.txt file;

默认 CMakeLists.txt 文件;

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.

注意:这个问题可能有一个更简单的解决方案,比如创建一个 C 项目而不是 C++ 项目,但我看不到,所以我必须让阅读这个问题的人可能有一个更简单的解决方案,然后手动编辑,谢谢。

回答by John Zwinck

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

从您提供的 CMake 文件中,您可以简单地删除该CMAKE_CXX_FLAGS行,或者用这样的 C 替换它:

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.

除了如您所说的将 main.cpp 重命名为 main.c 之外,其余的应该没问题。

回答by Rules

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

从 2016.3.2 版本开始,您可以在创建新项目时选择语言(C 或 C++)和项目类型(可执行文件或库)。

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

(尽管从我记事起,它就在 CodeBlocks 中))而且我仍然不知道我是否可以创建自己的“项目”。好吧,恕我直言,CLion 显然在这种方式上很糟糕,如果与 CodeBlocks 相比,我可以为几乎所有东西编写我的脚本并以这种方式自定义 IDE((()

screenshot 1screenshot 2
screenshot 3

screenshot 1screenshot 2
screenshot 3

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

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

PS:关于如何在https://youtrack.jetbrains.com/issues/CPP留下错误报告的截图
create_issue button