C++/OpenGL Compiling Issues

Associate
Joined
14 Jun 2010
Posts
737
Afternoon,

Unfortunately, I am having some problems with C++ and OpenGL that I have been trying to sort for the last few hours. I have to book "Beginning OpenGL Game Programming Second Edition" and I have completed a couple of exercises from it and they have compiled fine with G++ on Arch Linux.

However, I am now trying to compile a main.cpp file which includes headers called glxwindow.h and example.h. Each of the header files has its own .cpp file within which are the functions (Which have been prototyped in the headers). I am getting an error when trying to access functions within the classes defined in example.h and glxwindow.h.

Code:
// I have excluded the rest of the main.cpp file for brevity
Example example; // Creating an instance of the class
example.init();

This raises an error upon compiling with G++:
Code:
 main.cpp:(.text+0xb2): undefined reference to `Example::init()'

I stripped out all of the code from the main.cpp aside from the including of the header files and the main function, which instantiates a class and then calls a function from it- still no luck.

So I am stuck as to where to go from here, main.cpp includes header files, each with their own .cpp file, and tries to access functions from them, but it doesn't work.

Any help would be great. :)
 
Thank you for both of your replies, I tried running G++ as Andrew said and I got another error:

Code:
harvey ~/NetBeansProjects/Beginning OpenGL Chapter Two $ g++ main.cpp example.cpp glxwindow.cpp -lglut -lGL -lGLU -lX11
/usr/bin/ld: /tmp/ccQGjuhc.o: undefined reference to symbol 'XF86VidModeGetAllModeLines'
/usr/bin/ld: note: 'XF86VidModeGetAllModeLines' is defined in DSO /usr/lib/libXxf86vm.so.1 so try adding it to the linker command line
/usr/lib/libXxf86vm.so.1: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status

Trying to run it with the extra include generates another error:

Code:
harvey ~/NetBeansProjects/Beginning OpenGL Chapter Two $ g++ main.cpp example.cpp glxwindow.cpp -lglut -lGL -lGLU -lX11 -llibXxf86vm
/usr/bin/ld: cannot find -llibXxf86vm
collect2: error: ld returned 1 exit status
 
Thank you very much for all your help, Animatronic you were right about it, I replaced the term lib with -l and it compiled.

Once again, thank you everyone for you help. :)
 
Back
Top Bottom