Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: denisco on January 12, 2009, 07:10:53 am

Title: Compiler or codeblocks
Post by: denisco on January 12, 2009, 07:10:53 am
When I compile a .c with header containing C++ class and so on it generates error:

/home/denisco/workspace/iWebBrowser/DCString.h|167|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘DCString’

It does not do that with any other IDE I know eclispe, kdev...

Is it a compiler or codeblocks issue???

Title: Re: Compiler or codeblocks
Post by: stahta01 on January 12, 2009, 07:19:53 am
Programmer Issue!

Rename the c++ file with the proper cpp extension.

Tim S
Title: Re: Compiler or codeblocks
Post by: MortenMacFly on January 12, 2009, 07:22:42 am
When I compile a .c with header containing C++ class and so on it generates error:
It's generally bad design and in addition a bad idea to mix C and C++ code like that. GCC will be used to compile the C file (because of the file extension) which does simply not know C++ (and this is fully correct). Either you might want to try this with a C++ compiler or use the extern c clause (if possible) to mask the C++ part for a C compiler.
You can inspect the compiler command in Eclipse or whatever other IDE and compare it with yours to see what's different in the build processes. (See my sig on how to enable full logging therefore).
Title: Re: Compiler or codeblocks
Post by: Jenna on January 12, 2009, 07:39:31 am
The correct way is to rename the file(s) from .c to .cpp.

If you want to use c++, you should use c++ (and if possible the c++-version of the used system-headers).

Anyway you can try to force C::B to use the configured c++-compiler for your .c-file, by right-clicking the file in the management-pane and change "Properties... -> Advanced -> Compiler variable" to "CPP".

But be warned: playing with the advanced options of the build-system might lead to errors.