Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"lib" Prefix on Libraries

From http://www.adp-gmbh.ch/cpp/gcc/create_lib.html:

Note: the library must start with the three letters lib and have the suffix .a.

Is this an operating system convention, or a gcc/ar quirk? Xcode seems to be able to create libraries without the prefix. What's it doing differently?

like image 672
Maxpm Avatar asked Jun 03 '11 18:06

Maxpm


People also ask

What is the prefix for library?

"lib" Prefix on Libraries.

What are lib files C++?

lib file contains all the code and data for the library. The linker then identifies the bits it needs and puts them in the final executable. For a dynamic library, the . lib file contains a list of the exported functions and data elements from the library, and information about which DLL they came from.


Video Answer


1 Answers

You can name a library whatever you want, but if you want gcc's -l flag to find the right one, you need to name it the way that link describes. For example:

gcc -o myapp myapp.c -lm

Will compile myapp.c, link the resulting object with libm.a, and output an executable called myapp. These days, there might be a more complicated search path involving dynamic library names, etc., but you should get the basic idea from this example.

From the gcc man page:

-l library ...

... surrounds library with lib and .a and searches several directories.

like image 200
Carl Norum Avatar answered Sep 28 '22 03:09

Carl Norum