PuRe
PuRe

Reputation: 189

Core Dumped while creating shared library

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

Upvotes: 1

Views: 1260

Answers (1)

oxygene
oxygene

Reputation: 631

/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.

Upvotes: 1

Related Questions