Skip to main content

16.5) Using The Library


Suppose that data.hpp has been installed into /usr/local/include and libdata.a has been installed into /usr/local/lib.

Further suppose that the program that uses library is called prog.cpp.

To compile the program, we must use the -I option to indicate the location of the header file and the -L option to indicate the location of the library archive. The archive itself is identified using -l followed by its name (omitting the lib prefix and the .a suffix):

g++ -I/usr/local/include -L/usr/local/lib prog.cpp -o prog -ldata