News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Compiler or codeblocks

Started by denisco, January 12, 2009, 07:10:53 AM

Previous topic - Next topic

denisco

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???


stahta01

Programmer Issue!

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

Tim S
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

MortenMacFly

Quote from: 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:
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).
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

Jenna

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.