CodeBlocks, GCC: change project language c and c ++?

When I select a console project to start, it allows you to choose c or C ++, but after creating it .. I canโ€™t figure out where to change it, and when you create a win32 gui application, it doesnโ€™t give you an option at all, and by by default it is C ++ .. where can I go to c? I looked in all project settings for AGES. renaming my file from cpp to .c does not seem to do anything, it compiles the file as cpp. I know that without ide you just change your exe from g ++ to gcc, but how can I set this for the current project in code blocks?

+6
c ++ c windows codeblocks
source share
1 answer

The only tangible difference between choosing C vs C ++ when creating a project is which compiler is called for the translation units at build time. Currently, code blocks make it impossible to directly change this after creating a project. That is, you will have to change each source file one at a time to get what you want.

Here you can change it:

  • Open the properties window for the source you want to change. You can get to it by right-clicking the source file-> properties.

    alt text

  • Click the Advanced tab.
  • Find the Compiler variable field and change it from CPP to CC.

    alt text

  • Click OK.
  • Repeat this for each source file that you want to modify.

Now, if your existing project contains many source files, you can do it faster by manually editing the cbp codeblocks project file (it's just an xml file). The nodes you want to find and replace will look something like this:

<CodeBlocks_project_file> //... <Project> //... <Unit filename="source1.cpp"> <Option compilerVar="CPP" /> //change CPP to CC here </Unit> <Unit filename="source2.cpp"> <Option compilerVar="CPP" /> // and here </Unit> <Unit filename="source3.cpp"> <Option compilerVar="CPP" /> // and here then save. </Unit> //... </Project> </CodeBlocks_project_file> 

After the changes open your project in C :: B and confirm that it is compiled as the source file C. You should see the build log referencing gcc now instead of g ++.

+9
source share

All Articles