How do you use libraries?

I downloaded WildMagic from http://www.geometrictools.com/Downloads/Downloads.html and then I realized I don't know how to use it in my existing project.

So generally, what steps are required to use a library and in particular this one. I tried searching but I'm not sure what to search for.

Keywords: linking, building, running.. (I think)
Normally you need the library header (.h) and, unless it is only templates, the compiled lib file. So you will probably end up wanting something like:

1
2
#include <Custom Functions.h>
#pragma comment(lib,"Custom Functions") 


You will also have to make sure that you compiler is looking in the right place for the library and the header files.
What operating system are you on and what IDE + compiler are you using? The process differs a bit from OS to OS and from IDE to IDE. :)

-Albatross
In UNIX-like OSes:

If the library (headers and binaries) are installed under /usr/include and /usr/lib, you can typically just compile by specifying the library with the -l option of GCC.

For example, to use Boost.Regex, you can do:

g++ -lboost_regex main.cpp

This assumes that GCC is picking up the headers via the default include path that contains /usr/include. To have it look somewhere else for headers, you can specify that with this option: -I/somewhereelse/include.

Similary, the library is being found via the default library path that contains /usr/lib. To have it look somewhere else for libraries, you can specify that with the this option: -L/somewhereelse/lib.

Libraries on this platform are typically named libNAME.so or libNAME.a and the -l option just needs -lNAME.

man gcc for more information.

The generic steps to the process (any OS) are:
1) find the include path (where are the headers)
2) find the library path (where are the binaries)
3) add to the include path
4) add to the library path
5) add the library
6) #include a header
7) use it

3-5 are usually hidden under some project/config menus in IDEs.
Last edited on
Great feedback so far. I'm on a Windows machine using Code::Blocks. I just restored the folder to it's downloaded state because I had opened a Microsoft Visual C++ project (which I have also installed for cases like these) and tried to compile it with the play button :)

There's 15 folders in the root folder (including samples, license, documentation, ...) half of them have a Lib prefix to their names and contain headers. That's step 1.
Now it get's tricky. I can complete step 3 in "Build Options" by opening the "Search Directories" tab under "Linker" (there's also "Compiler" and "Resource Compiler")
But in "Link Libraries" under "Linker Settings" I tried searching for *.a *.so *.lib *.dylib *.bundle files but couldn't find a single one. So I need to compile it myself too. What do I compile? All the lib folders I guess. Will that do? Also won't that make *.o files?

I need a little more help.


I also added "C:\GeometricTools\" as an environment variable because it said in a PDF that I should do that.
Topic archived. No new replies allowed.