CodeBlocks、GCC:更改项目语言 c 和 c++?
当我选择开始控制台项目时,它允许您选择 C 或 C++。但一旦创建,我不知道如何更改它。另外,当您创建 Win32 GUI 应用程序时,它根本不提供该选项,并且其默认值为 C++。
哪里可以改成C?我多年来一直在寻找所有项目设置。将我的文件从 .cpp
重命名为 .c
似乎没有任何作用,它将文件编译为 C++。我知道如果没有 IDE,您只需将可执行文件从 g++
更改为 gcc
,但如何为 CodeBlocks 中的当前项目设置此设置?
When I select console project to start with, it lets you to select C or C++. But once its created, I can't figure out how to change it. Plus, when you create a Win32 GUI application, it doesn't give you the option at all and its default is C++.
Where can I change to C? I have been looking in all the project settings for ages. Renaming my file from .cpp
to .c
doesn't seem to do anything, it compiles the file as C++. I know that without the IDE, you just change your executable from g++
to gcc
, but how do I set this for the current project in CodeBlocks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建项目时选择 C 与 C++ 之间的唯一明显区别是在构建期间为翻译单元调用哪个编译器。 Code::Blocks 目前不提供在项目创建后直接更改此设置的方法。也就是说,您必须一次更改每个源文件才能获得您想要的内容。
您可以执行以下操作来更改它:
打开要更改的源的属性窗口。您可以通过右键单击源文件->属性来访问它。
找到编译器变量字段并将其从
CPP
更改为CC
。< /p>
现在,如果您现有的项目包含大量源文件,您可以通过手动编辑 Code::Blocks
.cbp
项目文件(它只是一个 XML 文件)来更快地完成此操作。您想要搜索和替换的节点将如下所示:更改后,在 Code::Blocks 中打开您的项目并确认它正在编译为 C 源文件。您现在应该看到构建日志调用
gcc
而不是g++
。The only tangible difference between selecting C vs C++ when you create a project is which compiler is invoked for the translation units during a build. Code::Blocks currently does not provide a way to directly change this after project creation. That is to say you would have to change each source file one at a time to get what you want.
Here's what you can do to change it:
Open the properties window for a source you want to change. You can get to it by right-click source file->properties.
Find the Compiler variable field and change it from
CPP
toCC
.Now if your existing project contains a lot of source files you can do this quicker by manually editing the Code::Blocks
.cbp
project file (it's just an XML file). The nodes you want to search for and replace will look something like this:After the changes, open your project in Code::Blocks and confirm it's being compiled as a C source file. You should see the build log invoking
gcc
now instead ofg++
.