I’m currently running a c++ project, with a class called Relation.
I’m trying to compile it, but I constantly get this error, regardless of the file extension that I’m using.
Compiler is cc, and the class I’m trying to compile, even when empty as below, causes this error.
I’ve tried the c++ header extensions, and the same errors occur.
#ifndef RELATION_H_
#define RELATION_H_
class Relation {
public:
Relation();
virtual ~Relation();
};
#endif
That’s the error you get when you try to compile C++ code with the C compiler.
You should check that your
cccompiler is actually capable of compiling C++ and what, if any, options are needed to make it do so.If it’s
gcc(and it certainly looks like it is, based on the absolutely identical error message), you may need to make sure that you’re callingg++rather thangccand/or that your extension for the source file (not header) is a recognised one, like.cpp(a).I’m not entirely certain the rules that
gccfollows but I’ve always found it safer to use source files likeblahblah.cppand explicitly useg++.(a) Reasoning: since you mention in your particular case that you’re using the correct header file extensions, I think one possibility is that the header extension has no effect whatsoever on what
gcctries to compile the source file as. It uses only the source file extension, as per the following transcript:In other words, I don’t think having an included header file of (for example)
xyzzy.hppwould force the compiler to compile C++ if the source file that’s including it is stillplugh.c.