Both Windows and Linux have static libraries and dynamic libraries. I used to develop dynamic libraries and static libraries in windows. I am not very familiar with the path of the Library in Linux.
I learned how to develop static and dynamic libraries in Linux.
I. Development in text mode
Refer to blog
Http://blog.csdn.net/liukun321/article/details/6912046
Http://blog.donews.com/dukejoe/archive/2006/01/12/691864.aspx
1. Static Library Development
Use imperative development
[Yuj @ localhost static_learn] $ VI static_test.cpp
[Yuj @ localhost static_learn] $ VI static_test.h
[Yuj @ localhost static_learn] $ g ++-C static_test.cpp
[Yuj @ localhost static_learn] $ ar R libtestadd. A static_test.o
Use the AR command to generate a static library.
Ar command:
The R parameter inserts the file into the static library file.
D. delete an object from the specified static library file.
M. Move the file to the specified file.
A. After adding the new target file (. O) to the static library file
Use static library
[Yuj @ localhost static_learn] $ VI static_main.cpp
Compile the test file and call the shouting in the library.
[Yuj @ localhost static_learn] $ g ++ static_main.cpp./libtestadd.
Or
[Yuj @ localhost static_learn] $ g ++ static_main.cpp-L.-ltestadd
2. Dynamic library development
[Yuj @ localhost static_learn] $ g ++-shared static_test.cpp-O libtestadd. So
Use this dynamic library
[Yuj @ localhost static_learn] $ g ++ static_main.cpp-ltestadd-L.
[Yuj @ localhost static_learn] $./A. Out
./A. Out: Error while loading shared libraries: libtestadd. So: cannot open shared object file: no such file or directory
The dynamic library cannot be found. How to find the path for Linux header files and libraries
Two methods to find the library
1. Modify the/etc/lD. So. conf configuration file to add the current path. Run/sbin/ Ldconfig
2. Modify Environment Variables
[Yuj @ localhost static_learn] $ export LD_LIBRARY_PATH =.: $ LD_LIBRARY_PATH
[Yuj @ localhost static_learn] $ ldd a. Out
Linux-gate.so.1 => (0x00cea000)
Libtestadd. So =>./libtestadd. So (0x00134000)
Libstdc ++. so.6 =>/usr/lib/libstdc ++. so.6 (0x06d2b000)
Libm. so.6 =>/lib/libm. so.6 (0x003b0000)
Libgcc_s.so.1 =>/lib/libgcc_s.so.1 (0x00dd0000)
Libc. so.6 =>/lib/libc. so.6 (0x001fa000)
/Lib/ld-linux.so.2 (0x001d4000)
[Yuj @ localhost static_learn] $./A. Out
Execution successful
Ii. Eclipse graphic interface development
1. The setting of eclipse is similar to that of VC.
Project-> properties-> C/C ++ build-> Settings-> tool settings-> gcc C ++ linker-> Libraries
Name of the added Library: libraries (-l): shared
Path for adding a database: library search path (-l ):
The static library and dynamic library settings are the same, but when the dynamic library is set to run, you need to add the corresponding path in/ECT/lD. So. conf, and run/sbin/ldconfig
Command to run