User forums > Help

How to build in C?

(1/2) > >>

purestr999:
I have looked in all the settings for hours for a way to fix this but I can't find an answer. I am new to programming so please post easy instructions if you can.
If I use the project wizard and make a C project, then everything works fine.
But if I use the file wizard and make a C file, or if I make a blank file and name it file.c, then when I try to compile programs, it compiles in C++. I do have a .c file from a few weeks ago that does compile in C, but if I copy it for example, its new copy won't.

For example: (somebody gave me this on another forum)

--- Code: ---#include<stdio.h>
int main ( ) {
#ifdef __cplusplus
  printf("Compiled as C++\n");
#else
  printf("Compiled as C\n");
#endif
  return 0;
}

--- End code ---
outputs "Compiled as C++"

and:

--- Code: ---#include <stdio.h>
#include <stdlib.h>

enum country {italy, america, france, brazil, england, newzealand, nepal, switzerland, canada, australia};
typedef enum country country;

int main(void)
{
    country tmpcountry;

    for(tmpcountry = 0; tmpcountry <= 9; ++tmpcountry)
        printf("%d\n", tmpcountry);
    return 0;
}
--- End code ---

has compile errors (because C++ doesn't let you do arithmetic with enum, but C does let you.



I can't make all my programs in projects for school reasons. Can anyone tell me simply how to fix this? Thanks!

Jenna:
Check if your c-compiler is set correctly ("Setup -> Compiler and debugger... -> GNU GCC Compiler -> Toolchain executables -> C compiler").

stahta01:
Remember files with ".c" extension are by default treated as C files under Code::Blocks.
Any other extension is treated as C++ file.

Turning on FULL compiler logging will help determine the real problem.

http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F

Tim S.

oBFusCATed:
purestr999: This is a known problem with 8.02, it is fixed in 10.05 and newer, so please update CB and recreate your project.
If you want to fix the project, right click the .c file -> properties -> advanced, then change the type from CC to C or something like that.

purestr999:
Thanks for the help everyone, especially oBFusCATed, I downloaded codeblocks from my universities site so I guess it was a couple years old >.> I installed the updated codeblocks and everything compiles fine now :)

Navigation

[0] Message Index

[#] Next page

Go to full version