Advertisement

compiling error

Started by November 03, 2005 05:46 AM
5 comments, last by AIRmichael 18 years, 11 months ago
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.
Try 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.
Advertisement
Quote: Original post by Spudder
Try 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 :(

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.
Quote: Original post by Hamster
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.


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
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.
Lead programmer of the (slowly evolving) syBR game engine --- http://sybr.sourceforge.net
Advertisement
Thx all for the info,

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

This topic is closed to new replies.

Advertisement