Odd linker issue "moving R_X86_64_32 against" - not a typical problem -fpIC

I have a strange problem when trying to create a bold shared library on Ubuntu 14.04 (64). Error messages are what you usually get if you forget to add -fPIC or a link to the wrong architecture library:

/usr/bin/ld: /usr/lib/libproj.a(pj_init.o): relocation R_X86_64_32 against 
`.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/lib/libproj.a: error adding symbols: Bad value

The first static library is compiled as follows:

gcc -c -fPIC -m64 NativeDB.c 

After that, you should create a single shared library using the library above, as well as several others (spatial, proj4, geos, sqlite):

gcc -shared -fPIC -m64 -o $@ $(OUT_DIR)/NativeDB.o $(OUT_DIR)/sqlite3.o $(SPATIALITE_DIR)/src/.libs/libspatialite.a $(SOME_OTHER_LIBS) 

Linking NativeDB.o to a shared library throws the specified linker error. Also note that a shared library can be created without NativeDB.o. Therefore, it becomes strange here because you see above how NativeDB.o is compiled and does not add an additional (implicit) binding.

Observations:

1) All libraries compiled properly. For example, I confirmed that libproj contains information about the move and is the correct architecture (via objdump -f):

...
pj_initcache.o:     file format elf64-x86-64
architecture: i386:x86-64, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x0000000000000000
...

This also applies to my own NativeDB.o file.

2) When gcc created lib is missing, the shared library is created perfectly (although, of course, without my library ...).

3). It is best to assume that the problem is due to the gcc weirdness when creating a shared library from static libraries containing 32-bit .text sections:

In archive target/libspatialite-4.2.1-rc0/src/.libs/libspatialite.a:

version.o:     file format elf64-x86-64

RELOCATION RECORDS FOR [.text]:
OFFSET           TYPE              VALUE 
0000000000000001 R_X86_64_32       spatialiteversion
0000000000000011 R_X86_64_32       spatialitetargetcpu
...
RELOCATION RECORDS FOR [.debug_info]:
OFFSET           TYPE              VALUE 
...
0000000000000307 R_X86_64_32       .debug_str+0x0000000000000256
0000000000000313 R_X86_64_64       spatialiteversion
0000000000000331 R_X86_64_32       .debug_str+0x000000000000022d
000000000000033d R_X86_64_64       spatialitetargetcpu

(version.o libspatialite.a). - ​​ :

mv version.o version_org.o
objcopy -O elf64-x86-64 target/libspatialite-4.2.1-rc0/src/.libs/version_org.o version64.o
# delete version.o from archive
ar -d libspatialite.a version.o
# add 64 bit version.o
ar -r libspatialite.a version.o

:

, gcc . , . , ( , ) OS X, clang build dynamiclib. , , , .

, :

, -. , ( JNI, ..).

, .

1

g++. , gcc. gcc vs g++.

0
1

eclipse: "-shared" (gcc c linker- > shared library settings- > Shared), . , . - exutable "Static library" eclipse "-shared" , . "-shared" .

, ,

0

All Articles