libpthread 链接器错误
Libpthread linker error
在编译一个简单的多线程程序时,我似乎无法链接 pthread 的共享对象。我收到以下错误:
/data/hunyadi/usr/bin/../lib/gcc/x86_64-pc-linux-gnu/7.1.0/../../../../lib64/libpthread.a(libpthread.o): In function `sem_open':
(.text+0x77cd): warning: the use of `mktemp' is dangerous, better use `mkstemp'
/cvmfs/cms.cern.ch/slc6_amd64_gcc491/external/gcc/4.9.1-cms/bin/ld: dynamic STT_GNU_IFUNC symbol `strcmp' with pointer equality in `/data/hunyadi/usr/bin/../lib/gcc/x86_64-pc-linux-gnu/7.1.0/../../../../lib64/libc.a(strcmp.o)' can not be used when making an executable; recompile with -fPIE and relink with -pie
collect2: error: ld returned 1 exit status
我尝试重新安装glibc
,但错误仍然存在。(使用CentOs 6
(。
请求的最小示例:
#include <future>
#include <iostream>
#include <string>
#include <vector>
int main()
{
try
{
auto test_lambda = [] (int a, int b, int c) -> void { std::cout << "a: " << a << " b: " << b << " c: " << c << "." << std::endl; };
std::future<void> test_future = std::async(test_lambda, 1, 2, 3);
std::chrono::milliseconds milliseconds_100(100);
while(test_future.wait_for(milliseconds_100) == std::future_status::timeout)
{
std::cout << "." << std::endl;
}
}
catch(const std::exception &e)
{
std::cout << e.what() << std::endl;
}
}
使用gcc 7.1.0
的编译器调用:
g++ src/test.cc -std=c++14 -pthread
上面的错误消息就是我得到的全部。
如果我添加 -fPIE 和 -pie,这是我收到此错误的输出:
g++ src/test.cc -std=c++14 -pthread -fPIE -pie
/cvmfs/cms.cern.ch/slc6_amd64_gcc491/external/gcc/4.9.1-cms/bin/ld: /data/hunyadi/usr/bin/../lib/gcc/x86_64-pc-linux-gnu/7.1.0/../../../../lib64/libpthread.a(libpthread.o): relocation R_X86_64_32S against `__stack_user' can not be used when making a shared object; recompile with -fPIC
/data/hunyadi/usr/bin/../lib/gcc/x86_64-pc-linux-gnu/7.1.0/../../../../lib64/libpthread.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
我设法通过本地安装gcc 5.3.0
并用它生成的文件替换libphread.so
文件来解决错误。
相关文章:
- Netbeans 10:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- CMake 错误:链接器命令失败,退出代码为 1 和 cpp.o 文件
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 如何修复 clang: 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- Android NDK.Build命令失败.未定义的引用.clang++:错误:链接器命令失败,退出代码为1
- 使用cmake错误链接boost日志
- 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用):在 Macbook 上
- C++ XCODE ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -
- clang:错误:链接器命令失败,C++代码中的退出代码为 1(使用 -v 查看调用)
- 静态库中的 g++ 错误链接函数
- 未定义的参考错误链接天然函数Android
- C++编译错误:ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v
- QT Q_PROPERTY错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- OSX MOJAVE -LD:架构X86_64 clang找不到符号:错误:链接器命令失败,出口代码1
- C 错误链接器命令失败了出口代码1(使用-V查看调用)
- LD:架构x86_64 clang找不到符号:错误:链接器命令失败,出口代码1(使用-v to See
- 聚输出错误 - 链接列表
- Xcode链接器错误:链接器命令失败,退出代码为1(使用-v查看调用)
- 尝试构建C DLIB示例无法与数百个未定义的参考错误链接