Author Topic: Implicit switch to C compiler?  (Read 11095 times)

Offline smallB

  • Almost regular
  • **
  • Posts: 193
Implicit switch to C compiler?
« on: October 24, 2011, 02:36:59 pm »
When I tried to create precompiled header following: http://wiki.codeblocks.org/index.php?title=Precompiled_headers
I started getting following error:
||warning: command line option '-Weffc++' is valid for C++/ObjC++ but not for C [enabled by default]|
||warning: command line option '-std=c++0x' is valid for C++/ObjC++ but not for C [enabled by default]|
C:\metaprogramming_excersizes\trying_c_compiler_not_in_toolchain\pr.h|6|error: C++ style comments are not allowed in ISO C90|
||=== Build finished: 1 errors, 2 warnings (0 minutes, 0 seconds) ===|

This project compiled before those steps from the link. Doesn't won't to compile after even though compiler is set to be C++ compiler. Is this a bug in Code::blocks or I'm doing something wrong?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12316
    • Travis build status
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline smallB

  • Almost regular
  • **
  • Posts: 193
Re: Implicit switch to C compiler?
« Reply #2 on: October 24, 2011, 03:12:17 pm »
Hi, I've read that already and cannot find anything relevant in there, can you?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12316
    • Travis build status
Re: Implicit switch to C compiler?
« Reply #3 on: October 24, 2011, 03:45:08 pm »
Hm, have you enabled the full log? I don't see the real errors in the log. Do you have .c files?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline smallB

  • Almost regular
  • **
  • Posts: 193
Re: Implicit switch to C compiler?
« Reply #4 on: October 24, 2011, 05:34:36 pm »
Hi this is the entire log from the compilation of a project:
Build started on: 24-10-2011 at 16:28.26
Build ended on: 24-10-2011 at 16:28.27

-------------- Build: Debug in trying_c_compiler_not_in_toolchain ---------------
 mingw32-gcc-4.6.1.exe -Wall -fexceptions -g -Wshadow -Winit-self -Wredundant-decls -Wcast-align -Wundef -Wfloat-equal -Winline -Wunreachable-code -Wmissing-declarations -Wmissing-include-dirs -Wswitch-enum -Wswitch-default -Weffc++ -Wmain -pedantic-errors -pedantic -std=c++0x -Wfatal-errors -Wextra -Wall -g -ID:\Libraries\boost_1_47_0\boost_1_47_0 -IC:\metaprogramming_excersizes\trying_c_compiler_not_in_toolchain -IC:\metaprogramming_excersizes\trying_c_compiler_not_in_toolchain -c C:\metaprogramming_excersizes\trying_c_compiler_not_in_toolchain\pr.h -o pr.h.gch
cc1.exe: warning: command line option '-Weffc++' is valid for C++/ObjC++ but not for C [enabled by default]
cc1.exe: warning: command line option '-std=c++0x' is valid for C++/ObjC++ but not for C [enabled by default]
C:\metaprogramming_excersizes\trying_c_compiler_not_in_toolchain\pr.h:6:8: error: C++ style comments are not allowed in ISO C90
 compilation terminated due to -Wfatal-errors.
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 2 warnings (0 minutes, 0 seconds)

The entire project looks like this:
#include <iostream>

using namespace std;
#include "pr.h"
int main()
{
    cout << "Hello world!" << endl;
    return 0;
}

#ifndef PR_H_INCLUDED
#define PR_H_INCLUDED

/*Nothing in this file, not even this comment*/

#endif // PR_H_INCLUDED//here cb shows the erroneous line (because of the comment)

No, I do not have .c files.

zabzonk

  • Guest
Re: Implicit switch to C compiler?
« Reply #5 on: October 24, 2011, 05:50:28 pm »
This is nothing to do with CB - it's a feature of MinGW GCC. If you do this from the command line:

mingw32-gcc-4.6.1.exe -std=c++0x d.h

you will get the same error, because you are using the gcc driver, and the driver cannot determine whether it is compiling C++ or C code from the file type, and so opts for C. You need to use the correct driver program, in this case mingw32-g++.exe or simply g++.

It's always a good idea to try compiling from outside CB if you have errors with GCC.




Offline smallB

  • Almost regular
  • **
  • Posts: 193
Re: Implicit switch to C compiler?
« Reply #6 on: October 24, 2011, 06:14:44 pm »
Hi Neil, thanks for your reply.
And indeed it works when I've switched to g++, but what if I have features in .h file that use c++11? Then g++ won't recognize them and mingw32-gcc-4.6.1.exe will want to compile them as C. What to do then?

zabzonk

  • Guest
Re: Implicit switch to C compiler?
« Reply #7 on: October 24, 2011, 06:18:49 pm »
If you use the -std=c++0x flag, why would g++ not recognise them?

Offline smallB

  • Almost regular
  • **
  • Posts: 193
Re: Implicit switch to C compiler?
« Reply #8 on: October 24, 2011, 06:42:28 pm »
Hi Neil, I'm quite a new user of code::blocks (previously I was using VS but just couldn't work with it anymore - many reasons, don't ask), and it never came to my mind that I can simply pass argument to a g++ to work in c++11 mode. Many thanks for your help.