GCC error can is used when making a shared object; Recompile with-fpic

Source: Internet
Author: User

There was an error when using Google Protobuf

/USR/BIN/LD:/USR/LOCAL/LIB/LIBPROTOBUF.A (MESSAGE_LITE.O): Relocation r_x86_64_32s against ' _ Ztvn6google8protobuf11messagelitee ' can not is used when making a shared object; Recompile WITH-FPI C
/usr/local/lib/libprotobuf.a:error adding Symbols:bad value
Collect2:error:ld returned 1 exit status

Searched, several articles are as follows:


View the entire compilation process, see no-fpic option during compilation, How to add in
Look at Protobuffer's readme and install documentation and see the need to add special compilation options that need to be introduced when the Configure is executed.
So make clean; Make Uninstall

. /configure cxxflags=-fpic
View the compiled file and discover that you have compiled the option-fpic, perform the compilation installation again
Recompile the program, this time no error, no errors, problem solving.

In addition answer;

Reason:
-fpic is a god horse stuff?
Option-fpic
PIC is an abbreviation for position-independent-codE. In a computer system, PIC and pie (position-independentexecutable) are target codes that can be executed in different locations in main memory. Pic is often used in shared libraries so that the same library code can be mapped to a single location for each program without worrying about overwriting other programs or shared libraries.

Because the so Dynamic library was compiled with-fpic, but the connected LIBPROTOBUF.A file is not -fpic generated, so the error.
That is to say that the connection Libprotobuf.aa file, also need to add the-fpic option to compile.

Gcc-fpic Options

With the-fpic option, the PIC code is generated: so is required for pic for dynamic linking purposes, otherwise, dynamic linking cannot be implemented. The main difference between Non-pic and PIC code is the difference between access global data and the jump label. For example, an Access global data directive, non-pic the situation is: LD R3, var1pic in the form of: LD R3, [email protected], meaning the GOT table from the index of Var1-offset Place Load a value at the address indicated by [email protected] 4 bytes is actually the address of the var1. This address is only known when it is running and is filled in by Dynamic-loader (ld-linux.so). Another example is the Jump label directive non-pic The situation is: jump printf, meaning to call printf. PIC is in the form of jump [email protected], which means jumping to the address indicated in the GOT table at index Printf-offset where the code is placed in the. plt section, where each external function corresponds to a code like this , its function is to call Dynamic-loader (ld-linux.so) to find the address of the function (in this case, printf), and then write its address to the GOT table where index is Printf-offset, and execute the function. This way, when you call printf for the 2nd time, you will jump directly to the address of printf without having to look for it. GOT is the data section, is a table, in addition to a few dedicated entry, each entry content can be re-executed when modified; the PLT is a text section, a section of code that does not need to be modified in execution. The mechanism for implementing PIC for each target is different, but very similar. For example, MIPS does not have. PLT, but is called. Stub, function and. Plt. It can be seen that dynamic link execution is complex and takes longer than static link execution; However, significant savings in size,pic and dynamic link technology are a very important milestone in the history of computer development.

/USR/BIN/LD:LIBS/X86_64/LIBGLOG.A (LIBGLOG_LA-LOGGING.O): Relocation r_x86_64_32s against ' _ Ztvn6google4base6loggere ' Can not is used when making a shared object; recompile with-fpic libs/x86_64/libglog.a: Could not read Symbols:bad value collect2: error:ld returned 1 exit status

You can only install the error provided method to reproduce the compilation libglog.a, and then replace the Libglog.

CXXFLAGS="-O3 -fPIC" ./configure --prefix=glog-0.3.3/install

参考:http://zrj.me/archives/1066

GCC error can is used when making a shared object; Recompile with-fpic

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.