next up previous contents
Next: Example Linking Zoo Program Up: Linking Previous: Name Mangling   Contents

Linker Options

Some of the more important linker options a beginner should know about are:-

-g
This instructs the linker to generate additional information to help when debugging. See section 6.1.6.

-o executable name
This tells the linker the name to give to the output file, for example:-

-o Zoo.exe

-Ldirectory
This tell the linker to look in the directory directory for libraries specified with the -l option (see below). The option can be used any number of times to define additional directories to be searched e.g.:-

g++ -L/cern/root/lib -LMyCode/lib ...

-llibrary_name
This tell the compiler to look for a library to load. It takes library_name and adds the prefix ``lib'' and the suffix either .a or .so and then looks for the library in each of the directories specified with the -L option. For example:-

g++ -L/cern/root/lib -LMyCode/lib -lZoo

would search for:-

/cern/root/lib/libZoo.so
/cern/root/lib/libZoo.a
MyCode/lib/libZoo.so
MyCode/lib/libZoo.a

and take the first match it finds.


next up previous contents
Next: Example Linking Zoo Program Up: Linking Previous: Name Mangling   Contents
P.D. Gronbech (IT Staff) 2015-10-02