Hi all,
I am getting a compile error. Yes, I have read the general notice before submitting issue. I am not going to ask a programming question.
The error I am getting is:
/home/xyz/Hello.h|7|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Hello’|
The code at that point is:
#ifndef HELLO_H
#define HELLO_H
class Hello { //Error happens here
public:
char greeting[6];
};
#endif
So the default gcc compiler is not recognizing the keyword "Class".
So My question is: how do I change the compiler from gcc to g++ using Code::Blocks?
I tried hand-editing the cbp file but it complained that the compiler could not located.
Suggestions?
PS: If it helps: I am writing a Nautilus extension and will be mixing a lot of C and C++ code.
thanks,
w|z0
A year ago, I had to work on a pure C project.
I had created (I think) a console project, than in the wizard I had chosen that the project is C, not C++.
Than every time I had added a file (through ctrl + shift(alt) + n) it was considered a C++ file, not C.
The way I had it fixed: choose the file in the tree -> properties -> switch the type of the file in the dialog
I don't know if this is a known and fixed problem, I will check it tonight, when I get home.
Edit:
I've done a test -> created console c project and added a file, the compiler is correctly chosen, but g++ is used for linking
Here is the full log
gcc -Wall -g -Werror=return-type -Woverloaded-virtual -c /home/obfuscated/projects/tests/test_c_proj/main.c -o .obj/Debug/main.o
gcc -Wall -g -Werror=return-type -Woverloaded-virtual -c /home/obfuscated/projects/tests/test_c_proj/test.c -o .obj/Debug/test.o
g++ -o bin/Debug/test_c_proj .obj/Debug/main.o .obj/Debug/test.o
cc1: warning: command line option "-Woverloaded-virtual" is valid for C++/ObjC++ but not for C
cc1: warning: command line option "-Woverloaded-virtual" is valid for C++/ObjC++ but not for C
Output size is 10,04 KB
Is that correct? I'm on linux 64bit gcc 4.3.3.
Maybe the GCC compiler should be split in two GCC C and GCC C++ compiler...
You need to surround your C headers with
#ifdef __cplusplus
extern "C" {
#endif
Your code
#ifdef __cplusplus
}
#endif
Name mangling in C and CPP is diffrent, with this you tell the c++ compiler that the files are C files and he knows what to do.