Creation and calling of Linux/Eclipse/C ++ dynamic library
Create a dynamic link library
Create a C ++ project in eclipse, file-> New-> Project-> C ++ project, and select shared library.
After compilation, A libshared. So file will be generated under the project directory, which is the dynamic link library file we will use.
Import dynamic library
Project-> properties-> C/C ++ build-> Settings-> tool settings-> gcc C ++ linker-> libraries, add libraries (-l): shared, add library search path (-l): {compiled *. so file path }.
Now the compilation can be passed and runProgramYou also need to specify the default dynamic library search path. There are two methods. One is to modify the default search path of the system, similar to adding environment variables. The other is to compile the path information of the dynamic link library into a binary executable file.
First, add the dynamic library path to/etc/lD. So. conf, and then run ldconfig to take effect. Or export LD_LIBRARY_PATH = path. Both methods take effect only outside eclipse. The latter can only be used on the same terminal. In eclipse, you can set run_configurations-> environment to add the environment variable LD_LIBRARY_PATH.
Type 2: Tool Setting-> gcc C ++ linker-> miscellaneous-> other options add-r/path. After a program is generated using this method, the path of the dynamic link library cannot be changed.
Of course, there is also the simplest and practical method to put the dynamic link library directly under the default path of the system:/lib or/usr/lib.
How to compile C/C ++ in Linux eclipse and add the Link Library
Right-click Project-> properties-> C/C ++ builder-> Settings to add compiler and linker parameters.
For example, you can add the-lhello library in the library of linker, or you can add the search path of the hello library-l
For example:
The pthread library is not the default library in Linux. You must use the static library libpthread. A during connection.
Therefore, when you use pthread_create () to create a thread and call the pthread_atfork () function to create a fork handler, You need to link the database.
The solution is as follows:
Add the-lpthread parameter to the compilation.
Gcc-O pthread. C-lpthread
You can add pthread to libraries (-l) in libraries in gcc C linker, And remember-l it has been added by default.
The above content is transferred from http://hi.baidu.com/kakakun1/blog/item/22b4b6386e9b193eb9998fe7.html
In fact, you only need to set the properties to import the Linux DLL. The final import format is shown in.
The figure shows that the DLL in eclipse is in the same format as the referenced file, and the path and name are specified in the project attribute in. This is the difference between the two.