# compiling error

This topic is 4495 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey, I am trying to compile the following in the redhat terminal: main.c Test.c Test.h gcc main.c Test.c -o test But what I get is the following: Test.h:1: error: syntax error before "Test" Test.h:2: error: syntax error before '{' token In file included from Test.c:1: Test.h:1: error: syntax error before "Test" Test.h:2: error: syntax error before '{' token Test.c:3: error: syntax error before ':' token Does any one know how to fix this? Test.c contains: #include "Test.h" void Test::bla() { int a = 0; } and Test.h contains: class Test { public: void Test::bla(); }; and the main.c contains "#include Test.h" What is wrong with it? Do I have to make a seperate makefile or something? If so, how would that be possible? Greetings, Michael L.

##### Share on other sites

class Test{public:void bla();  //<--- no "Test::" before function name};

and see if that does the trick, you only need the class_name:: in source files (.cpp), not in headers files.

##### Share on other sites
Quote:
 Original post by SpudderTry declaring your class like this instead:class Test{public:void bla(); //<--- no "Test::" before function name};and see if that does the trick, you only need the class_name:: in source files (.cpp), not in headers files.

I fixed that now, but I still have the same error :(

##### Share on other sites
Try replacing gcc on the command line with g++. I think (although I may be wrong) that vanilla gcc only deals with straight C unless you fire strange command line switches at it. g++ is the C++ version.

##### Share on other sites
Quote:
 Original post by HamsterTry replacing gcc on the command line with g++. I think (although I may be wrong) that vanilla gcc only deals with straight C unless you fire strange command line switches at it. g++ is the C++ version.

Thx alot, I had to do some adjustments (My linux didnt recognize a function called exit (useing a tutorial from nehe) so i had to remove that, and link only the GLUT library manually.

So this works:

g++ -o test main.c Test.c -lglut

##### Share on other sites
Hi!

I think you should change your file name from Test.c to Test.cpp. IIRC gcc can detect if your file must be compiled as C or C++ source but the extension must be correct.

Just my 2 cents.

##### Share on other sites
Thx all for the info,

And btw, exit works for me now as well. Was probably a linkage problem or something.