Use eclipse to develop C ++ dynamic link library programs in Linux

Source: Internet
Author: User

Comprehensive sorting from networks.

In Linux, DLL conversion methods are similar to those in windows, but the names are different. In Linux, a dynamic link is called a standard object, and the generated Dynamic Link file is *. So. For more information, see related documents.

Development Environment: Eclipse 3.4.2

G ++: 4.3.2

1. Create a dynamic link library

(1) create a C ++ project in eclipse

File-> New-> Project-> C ++ project, and select shared library.

(2) createSource codeFile

File-> New-> source file, with the specified name shared. CC

(3) Compile the source code

/** Test. CC ** created on: Oct 10,200 9 * Author: created y*/# Include<Iostream>Using NamespaceSTD;VoidShow () {cout<"Shared library."<Endl ;}
The relocation r_x86_64_32 against 'a local sympost' error occurs during dynamic library compilation.

The following error occurs when compiling a dynamic library:

...

... Relocation r_x86_64_32 against 'a local symbol' can not be used when making a shared object; recompile with-FPIC

... Cocould not read symbols: Bad Value

Solution: the compiler prompts "recompile with-FPIC ".

But who should we re-compile with this parameter? After several times of hard work, I found the following situations:

1. When compiling the. o file, the parameter-FPIC is not added. This problem does not occur in GCC version 3.4.6. Maybe the compiler will add it by default.

2. CurrentProgramA static library is used. The static library does not include-FPIC when compiling the. o file (the static library is actually a. o file package ).

Note: I found that this problem is not solved even if-FPIC is not added when the makefile is handwritten. This problem is very depressing because it only appears when the. A file is compiled using automake.

If you understand the cause, the solution will naturally be available. Make sure that-FPIC is added when you compile the. o file so that you can compile the dynamic library.

For example, note: parameters must be added to the compiler and connector.

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.