Recently I have tried to compile a program in g++ (on Ubuntu). Usually i use Dev-C++ (on Windows) and it works fine there as long as I make a project and put all the necessa
You can also check for correct #include
tags within filename.cpp
. Assume that filename.cpp
uses code contained in myclass.h
present in the same directory as filename.cpp
. Assume that the class that g++ says is undefined is contained in myclass.h
and defined in myclass.cpp
. So, to correctly include myclass.h
within filename.cpp
, do the following:
filename.cpp
:#include
#include
//..source code.
filename.o: myclass.C myclass.h filename.cpp
g++ -I./ -c filename.cpp -o filename.o
myclass.o: myclass.C myclass.h
g++ -c myclass.C -o myclass.o
In the above, note the use of -I.
option when compiling filename.cpp
. The -I
asks g++
to include the path following the -I
part into the search path. That way myclass.h
is correctly included.
In the absence of more information (the source maybe), it is difficult to say with any accuracy where the problem lies. All attempts will be but stabs in the dark.