Two Linux-link library (DLL, static library, library naming rules, establish a connection without the version number of the software file)

http://www.cppblog.com/wolf/articles/74928.html

http://www.cppblog.com/wolf/articles/77828.html

http://www.jb51.net/article/34990.htm

1. Concept and difference:
    a static library is a collection of object files during compilation. Static library linked when the program is used, the linker will be used in the program code for the function to copy from the library file into the application. Once the link is complete, in the implementation of the program does not need a static library. 
    Since each application using a static library will need to copy the code function is used, it is statically linked file will be relatively large.

    Relative to a static library, dynamic library at compile time and has not been compiled into object code, but only to make some mark. Then when the program started running, dynamically load the required modules, so the dynamic library generated executable file is relatively small. Since the library is not integrated into your application, but dynamic application and call the program is running, so the operating environment of the program must provide the appropriate library. Change the dynamic library does not affect your programs, so upgrading dynamic libraries more convenient.

2. Name:
    name of the static library is generally libxxxx.a, where xxxx is the name of the lib.
    The name of the dynamic library is generally libxxxx.so.major.minor, xxxx is the name of the lib's, major is the major version number, minor is the minor version number. The version number can be no general will establish a connection without the version number of the software file link to the full name of the library file.

3. Create:
whether static or dynamic library library are created in two steps, the first step to create the target file, the second step the production library.
1) Create a static library:.
#Gcc -c test.c -o test.o
#ar RCS libtest.a test.o
name as a static library libtest.a on production, which options:
r indicates that the module added to static library;
c represents the creation of a static library;
S represents production index;
there are more options like add, delete object files in the library, including the static library unpacking, etc. can be obtained by man.
2) create a dynamic library:.
#Gcc -fPIC -o -c test.c test.c
#gcc --share test.o -o libtest.so
-fPIC for cross-platform

4. Use:
methods of compiling and linking the object program is the same:
. #Gcc -ltest -o main main.c -L
. -L catalog under the specified search base now, and if not, the system will default to the directory search, generally under / lib, / usr / lib.
For static library, then this step can be libtest.a library deleted, because it has been compiled into a target program, no longer need it.
For a dynamic library, libtest.so library just made a mark in the target program, will be dynamically loaded when you run the program, then where to load it? Load directory will be specified by /etc/ld.so.conf, usually the default is / lib, / usr / lib, so to get a smooth dynamic libraries to load, you can copy the library files to the top two directories, or setting export LD_LIBRARY_PATH = $ LD_LIBRARY_PATH: / XXX / YYY, back to your own dynamic library catalog, then or modify /etc/ld.so.conf file, the path where the library is added to the end of the file, and execute ldconfig refresh. In this way, all the library files added to the directory are visible.

In addition there is a need to understand file /etc/ld.so.cache, which holds a commonly used dynamic libraries, and they will first be loaded into memory because the memory access speed is far greater than the access speed of the hard drive, so you can increase the speed of the software load dynamic library of.

Finally mention that, when the same directory there are both dynamic library static library, and the library of the same name two, will compile time how to link it?

The default is a compile-time dynamic linking gcc, if you want to specify a priority link static library, you need to specify the parameters of static.

http://www.cppblog.com/wolf/articles/74928.html

http://www.cppblog.com/wolf/articles/77828.html

http://www.jb51.net/article/34990.htm

1. Concept and difference:
    a static library is a collection of object files during compilation. Static library linked when the program is used, the linker will be used in the program code for the function to copy from the library file into the application. Once the link is complete, in the implementation of the program does not need a static library. 
    Since each application using a static library will need to copy the code function is used, it is statically linked file will be relatively large.

    Relative to a static library, dynamic library at compile time and has not been compiled into object code, but only to make some mark. Then when the program started running, dynamically load the required modules, so the dynamic library generated executable file is relatively small. Since the library is not integrated into your application, but dynamic application and call the program is running, so the operating environment of the program must provide the appropriate library. Change the dynamic library does not affect your programs, so upgrading dynamic libraries more convenient.

2. Name:
    name of the static library is generally libxxxx.a, where xxxx is the name of the lib.
    The name of the dynamic library is generally libxxxx.so.major.minor, xxxx is the name of the lib's, major is the major version number, minor is the minor version number. The version number can be no general will establish a connection without the version number of the software file link to the full name of the library file.

3. Create:
whether static or dynamic library library are created in two steps, the first step to create the target file, the second step the production library.
1) Create a static library:.
#Gcc -c test.c -o test.o
#ar RCS libtest.a test.o
name as a static library libtest.a on production, which options:
r indicates that the module added to static library;
c represents the creation of a static library;
S represents production index;
there are more options like add, delete object files in the library, including the static library unpacking, etc. can be obtained by man.
2) create a dynamic library:.
#Gcc -fPIC -o -c test.c test.c
#gcc --share test.o -o libtest.so
-fPIC for cross-platform

4. Use:
methods of compiling and linking the object program is the same:
. #Gcc -ltest -o main main.c -L
. -L catalog under the specified search base now, and if not, the system will default to the directory search, generally under / lib, / usr / lib.
For static library, then this step can be libtest.a library deleted, because it has been compiled into a target program, no longer need it.
For a dynamic library, libtest.so library just made a mark in the target program, will be dynamically loaded when you run the program, then where to load it? Load directory will be specified by /etc/ld.so.conf, usually the default is / lib, / usr / lib, so to get a smooth dynamic libraries to load, you can copy the library files to the top two directories, or setting export LD_LIBRARY_PATH = $ LD_LIBRARY_PATH: / XXX / YYY, back to your own dynamic library catalog, then or modify /etc/ld.so.conf file, the path where the library is added to the end of the file, and execute ldconfig refresh. In this way, all the library files added to the directory are visible.

In addition there is a need to understand file /etc/ld.so.cache, which holds a commonly used dynamic libraries, and they will first be loaded into memory because the memory access speed is far greater than the access speed of the hard drive, so you can increase the speed of the software load dynamic library of.

Finally mention that, when the same directory there are both dynamic library static library, and the library of the same name two, will compile time how to link it?

The default is a compile-time dynamic linking gcc, if you want to specify a priority link static library, you need to specify the parameters of static.

Guess you like

Origin www.cnblogs.com/liuzhenbo/p/11031132.html