c++ - 创建共享库时发生核心转储

标签 c++ linux ubuntu g++

当我试图在我的 ubuntu 14.04 64 位系统上创建一个共享库时,我刚遇到这个错误:

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.

我还尝试从一个带有空构造函数和空析构函数的简单类创建一个简单的共享库,但出现了同样的错误。

谁能帮我解决这个问题? 如果需要更多信息,我可以告诉他们。

pure@pure-QOSMIO-X500:~$哪个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.

还有这个:

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

现在返回:

/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/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 编译目标代码。

PIC 代表位置独立代码,对于共享库来说是必需的,因为它们在内存中的位置事先是未知的。例如,使用 -fPIC 生成的代码使用相对而非绝对地址进行跳转。

关于c++ - 创建共享库时发生核心转储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25665273/

相关文章:

regex - 用于检查字符串的 Shell 脚本正则表达式

c - getrusage(RUSAGE_THREAD, &r_usage) 中的用户 CPU 时间和系统 CPU 时间到底测量什么?

docker - 连接总线失败 : Host is down in ubuntu

linux - 当我在 ubuntu 终端中运行程序时,如何摆脱 "./"?

c++ - `ifreq` 结构中的 IPv6 地址问题

c++ - 埃拉托斯特尼筛法 C++ 无限循环

c++ - 我创建的 Microsoft Visual C++ 2008 Express Edition : Can I insert default code in every . cpp 文件?

linux - 有没有办法使用 netlink 在两个用户空间进程之间进行进程间通信 (IPC)?

c++ - 将 ASM jmp 内联到新内存

ubuntu - 在 ubuntu 中运行 pcl/tools/mesh2pcd.cpp