Author Topic: Compiler or codeblocks  (Read 4317 times)

Offline denisco

  • Single posting newcomer
  • *
  • Posts: 8
Compiler or codeblocks
« 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???


Offline stahta01

  • Lives here!
  • ****
  • Posts: 7786
    • My Best Post
Re: Compiler or codeblocks
« Reply #1 on: January 12, 2009, 07:19:53 am »
Programmer Issue!

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

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

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Compiler or codeblocks
« Reply #2 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).
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Compiler or codeblocks
« Reply #3 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.