When compiling a C++ program on linux using g++, how do you link in your own header files?
For example I have a file with the following includes:
#include <stdlib.h>
#include <GL/glut.h>
#include <math.h>
#include <stdio.h>
#include "3DCurve.h"
When I compile using the following command:
g++ -lm -lglut -lGL -o 3dcurve Example_8_1.cpp
I get the following error:
undefined reference to 'draw3Dcurve(double, double, double, double, double, double)'
How do I link the the 3DCurve.h file into the compiler? The header file and its implementation sit in the same folder as the file I’m compiling. My understanding is that the compiler should just find it, if it is sitting in the same folder.
What am I not getting?
One doesn’t link to header files, one just includes them. But if the header file has a corresponding implementation file, you either have to include that in the compilation line, or make an object file out of that, and include that in the compilation line. From your error, it looks like you have an implementation file that hasn’t been dealt with appropriately.
Assuming the implementation if
DCurve.his called3DCurve.cppthen you could do this:Other options are to make an object file
3DCurve.ousing the-cg++ option, and thenOr, make a shared or static library and use it like you would another 3rd party library.