1
votes

I just got this error when I tried to create a shared library within on my ubuntu 14.04 64 bit system:

g++ -Wall -g -Iinclude -c /home/pure/Schreibtisch/TestDLL/src/test.cpp -o obj/Debug/src/test.o

g++ -shared  obj/Debug/src/test.o  -o bin/Debug/TestDLL.so  
collect2: error: ld terminated with signal 6 [Abgebrochen], core dumped
/usr/bin/ld: ld: wcsrtombs.c:99: __wcsrtombs: Zusicherung »data.__outbuf[-1] == '\0'« nicht erfüllt.

I also tried to make a simple shared library from a simple class with an empty constructor and an empty destructor, same error came.

Can anyone help me how to fix that? If more informations are needed, I can tell them.

pure@pure-QOSMIO-X500:~$ which g++

/usr/bin/g++

pure@pure-QOSMIO-X500:~$ g++ --version

g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2 Copyright (C) 2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

And this:

LC_ALL=C g++ -shared /home/pure/Schreibtisch/TestDLL/obj/Debug/src/test.o -o /home/pure/Schreibtisch/TestDLL/libTestDLL.so

returns now:

/usr/bin/ld: /home/pure/Schreibtisch/TestDLL/obj/Debug/src/test.o: relocation R_X86_64_32S against `_ZTV4test' can not be used when making a shared object; recompile with -fPIC /home/pure/Schreibtisch/TestDLL/obj/Debug/src/test.o: error adding symbols: Bad value collect2: error: ld returned 1 exit status

1
Analyze the core file with gdb. - 0x499602D2
Try building the same source code on an English system. - John Zwinck
Yes, please do something like export LC_ALL=C (or similar for your shell) before starting the compile process. - Florian Keßeler
Could you tell us whether you are using a stock compiler and binutils or whether you have installed custom versions? Please execute which g++ and g++ --version and tell us the output. - oxygene
@FlorianKeßeler Setting the locale to C beforehand is really needed to successfully compile a shared library with g++? Is this a joke or just a bug in older compilers? - Youka

1 Answers

1
votes

/usr/bin/ld: /home/pure/Schreibtisch/TestDLL/obj/Debug/src/test.o: relocation R_X86_64_32S against `_ZTV4test' can not be used when making a shared object; recompile with -fPIC /home/pure/Schreibtisch/TestDLL/obj/Debug/src/test.o: error adding symbols: Bad value collect2: error: ld returned 1 exit status

I don't know why you get a crash with your native locale (german) and an useful error message using default locale. However, now the linker itself tells you what's wrong: You didn't compile your object code with -fPIC.

PIC stands for position independent code and is necessary for shared libraries because their location in memory is not known in advance. For example, code generated with -fPIC uses relative and not absolute addresses for jumps.