How to add. A static Link Library and dynamic library to eclipse

Source: Internet
Author: User
How to add. A static Link Library and dynamic library to eclipse

Add the. A static link library to eclipse.

Project-> properties-> C/C ++ build-> tool settings-> miscellaneous-> other objects: Add **. A to the file system.

----------------------------------------------------------- Cute split line ----------------------------------------------------------

(1) http://linux.chinaunix.net/bbs/archiver? Tid-974839.html

Linux dynamic library
[B] dynamic library usage in Linux [/B] [B] [/B]
Basic concepts of static and dynamic libraries
Static Database is executable Program The connection has been added to the Execution Code and physically become a part of the execution program. When you use a static library to compile a program, you do not need to support this library file. It can be used anywhere, but it is generated.
The executable file of is large. The dynamic library is loaded into the execution program when the executable program starts and can be shared by multiple executable programs. The program generated by using dynamic library compilation is relatively small, but the database file support is required during running. If these database files are not in the machine, they cannot be run.
2.
How to use dynamic library
How the program uses the shared library during connection is required
Required
You can find the location of the shared library during running. In Linux, the executable program searches for the/lib and/usr/lib directories by default.
Search for absolute paths in/etc/lD. So. conf. Linux also provides the environment variable LD_LIBRARY_PATH for users to choose from.
Set it to find other paths except the default path, for example, to find the/work/lib path, you can go to/etc/rc. d/RC. local or other systems can be executed after startup
Script
Add the following statement: LD_LIBRARY_PATH =/work/lib: $ (LD_LIBRARY_PATH ). In addition, the LD_LIBRARY_PATH path takes precedence over the default path of the system.
LD_LIBRARY_PATH).
However, LD_LIBRARY_PATH is set globally. Excessive use of LD_LIBRARY_PATH may affect the operation of other applications. Therefore, LD_LIBRARY_PATH is mostly used for debugging. (For LD_LIBRARY_PATH defects and usage guidelines, see why
LD_LIBRARY_PATH is bad). We recommend that you use the-R or-rpath option of GCC to specify the library search path during compilation, and save the library path information in the executable file, at runtime, it will go directly to this path
Path Search Library to avoid using the LD_LIBRARY_PATH environment variable search.
3. Path and runtime path of the database connection
The modern connector separates the link-time path and the run-time path when processing the dynamic library, you can use-L to specify the path of the database to be connected, and use-R (or-rpath) to specify the path of the database to run the program. This greatly improves the flexibility of the database application. For example, we do embedded
During transplantation # arm-Linux-GCC $ (cflags)-O target-L/work/lib/zlib/
-Llibz-1.2.3 (work/lib/zlib is a cross-compiled zlib library), after the target is compiled, we just need to copy the zlib library to the default path of the development board system. You can also use-rpath (or-R) and LD_LIBRARY_PATH to specify the search path.

Bytes ------------------------------------------------------------------------------------------------------------------------

In Linux, the static Link Library is the. A file, and the dynamic link library is the. So file. This article describes how to create and use dynamic link libraries using eclipse in Linux.

1. Create a dynamic link library in eclipse

1. New> Project> C ++ Project

Select Share library-> Empty Project, enter Project name: share, and click Finish to create the project.


2. write code in the share project or introduce the file system.

(How to introduce the file system: Right-click the share project-> Import-> General-> File System-> select the file to be created as a dynamic link library)

3. If you need to call other dynamic link libraries in the share project, you need to add other dynamic link libraries (the addition method is the same as that in the dynamic link library below) and compile the libraries. Otherwise, compile directly.

After compilation, the libshare. So file will be generated in the DEBUG directory, which is the dynamic link library we need.

 

Ii. Use of Dynamic Link Library:

Note the following three points:

1. Add the share project path to the include search path of the project (that is, the path of the Dynamic Link Library Project), because the header file (. h file) must be used during compilation)

2. Add the dynamic link library to be searched. Here is libshare. So and the search path.

3. Tian
Add the environment variable LD_LIBRARY_PATH and its value is the path of the share project (that is, the dynamic link library ).
Project path ). Or compile the address of the dynamic link library into the project (this method is useful when the dynamic link library needs to call other dynamic link libraries created by itself ). Another method is
Copy the dynamic link library to the/usr/lib or/lib directory.

Refer:

When running, the system searches for the dynamic link library (libshare) in the path contained in LD_LIBRARY_PATH. so, of course, the system will also find dynamic link libraries in the/usr/lib and/lib directories by default.

The specific method is as follows:

1. Create a Project New> C ++ project> executable> Empty Project

Project name: Mass

2. Writing requiredCodeContains the dynamic link library, which is libshare. So.

Right-click the project mass-> properites-> C/C ++ build-> Settings-> tool settings


Select gcc C ++ linker-> libraries. in the upper-right window, click the + plus sign to add share. Click the + plus sign in the following window to add "$ {workspace_loc:/share/debug }"

(/Share/debug is the path of libshare. So)

3. Add include search path


Select C/C ++ general-> path and symbols-> reference. All project names are displayed. Select Share project, this will automatically add the share path to the include search path.

Note: It is best to select all deployments in the configuration column.
4. Add the LD_LIBRARY_PATH environment variable.
Right-click the mass project and choose run as> RUN deployments. A window is displayed.

Select mass project on the left-> environment-> new to add environment variables.

You can also compile the path of the dynamic link library into the project without adding LD_LIBRARY_PATH.

Refer:

5. Compile and run the program.

reference: http://www.tayefeh.de/2009/07/creating-and-using-a-c-shared-library-with-eclipse-cdt-galileo-and-gnu-c-compiler-and-linker/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.