Core Dumped在创建共享库时 [英] Core Dumped while creating shared library
问题描述
我在我的ubuntu 14.04 64位系统上尝试创建共享库时遇到此错误:
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:〜$ g ++
pure@pure-QOSMIO-X500:~$ which g++
/ usr / bin / g ++
/usr/bin/g++
pure @ pure-QOSMIO-X500 :〜$ g ++ --version
pure@pure-QOSMIO-X500:~$ g++ --version
g ++(Ubuntu 4.8.2-19ubuntu1)4.8.2
版权所有自由软件基金会,
这是免费软件;请参阅复制条件的来源。有NO
保修;
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.
这样:
LC_ALL = C g ++ -shared /home/pure/Schreibtisch/TestDLL/obj/Debug/src/test.o -o /home/pure/Schreibtisch/TestDLL/libTestDLL.so
LC_ALL=C g++ -shared /home/pure/Schreibtisch/TestDLL/obj/Debug/src/test.o -o /home/pure/Schreibtisch/TestDLL/libTestDLL.so
现在返回:
/ usr / ld:/home/pure/Schreibtisch/TestDLL/obj/Debug/src/test.o:对于`_ZTV4test'重定位R_X86_64_32S不能在创建共享对象时使用;重新编译-fPIC
/home/pure/Schreibtisch/TestDLL/obj/Debug/src/test.o:错误添加符号:错误值
collect2:错误:ld返回1退出状态
/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
推荐答案
/ usr / bin / ld:/ home / pure / Schreibtisch /对于`_ZTV4test',当
创建一个共享对象时,不能使用TestDLL / obj / Debug / src / test.o:
重定位R_X86_64_32S; 使用-fPIC重新编译
/home/pure/Schreibtisch/TestDLL/obj/Debug/src/test.o:错误添加
符号:错误值collect2:错误:ld返回1退出状态
/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
我不知道为什么会遇到与您的本机语言环境(德语)语言环境。但是,现在链接器本身告诉你出了什么问题:你没有使用 -fPIC
编译目标代码。
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 代表位置无关代码 ,对于共享库是必需的,因为它们在内存中的位置是未知的。例如,使用 -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.
这篇关于Core Dumped在创建共享库时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!