gpt4 book ai didi

c++ - 红帽 : using compiles fine but linker can't find __atomic_store_16; what library?

转载 作者:行者123 更新时间:2023-12-02 09:56:29 28 4
gpt4 key购买 nike

我正在使用 atomic<>第一次,就像使用 <thread>需要你链接一个线程库,好像使用<atomic>要你做……某事。什么?

> uname -a
Linux sdclxd00239 3.10.0-693.11.6.el7.x86_64 #1 SMP Thu Dec 28 14:23:39 EST 2017 x86_64 x86_64 x86_64 GNU/Linu

> g++ Foo.cxx -g -o MsgQueueNoLock -pthread
/tmp/ccnGOKUG.o: In function `std::atomic<Ptr_T>::store(Ptr_T, std::memory_order)':
/opt/rh/devtoolset-7/root/usr/include/c++/7/atomic:239: undefined reference to `__atomic_store_16'
/tmp/ccnGOKUG.o: In function `std::atomic<Ptr_T>::load(std::memory_order) const':
/opt/rh/devtoolset-7/root/usr/include/c++/7/atomic:250: undefined reference to `__atomic_load_16'
collect2: error: ld returned 1 exit status>

g++ Foo.cxx -g -o Foo -pthread
/tmp/ccnGOKUG.o: In function `std::atomic<Ptr_T>::store(Ptr_T, std::memory_order)':
/opt/rh/devtoolset-7/root/usr/include/c++/7/atomic:239: undefined reference to `__atomic_store_16'
/tmp/ccnGOKUG.o: In function `std::atomic<Ptr_T>::load(std::memory_order) const':
/opt/rh/devtoolset-7/root/usr/include/c++/7/atomic:250: undefined reference to `__atomic_load_16'
collect2: error: ld returned 1 exit status

更新:我需要使用 -latomic .很公平!但是我找不到一个我可以实际使用的。

首先我看下 /usr/lib ,我看到我在 gcc/.../4.8.2 下有一个 simlink指向 gcc/.../4.8.5 ?!!?我一生中从未见过旧版本依赖于新版本,尽管时间戳使我怀疑过去有人手动干预或复杂的历史。
> l `find /usr/lib -name '*atomic*'`
-rw-r--r--. 2 root root 1379 Jul 13 2017 /usr/lib/python2.7/site-packages/sos/plugins/atomichost.pyo
-rw-r--r--. 2 root root 1379 Jul 13 2017 /usr/lib/python2.7/site-packages/sos/plugins/atomichost.pyc
-rw-r--r--. 1 root root 1672 Jul 13 2017 /usr/lib/python2.7/site-packages/sos/plugins/atomichost.py
-rw-r--r-- 1 root root 40 Sep 22 2017 /usr/lib/gcc/x86_64-redhat-linux/4.8.2/libatomic.so
-rw-r--r-- 1 root root 38 Sep 22 2017 /usr/lib/gcc/x86_64-redhat-linux/4.8.2/32/libatomic.so
lrwxrwxrwx 1 root root 44 Jul 3 2018 /usr/lib/gcc/x86_64-redhat-linux/4.8.2/32/libatomic.a -> ../../../i686-redhat-linux/4.8.5/libatomic.a

网上的一些东西暗示我可能会在 /usr/local/lib 下找到快乐但事实上快乐是找不到的:
> find /usr/local/lib -name '*atomic*'
>

实际安装的 gcc 是旧的(4.8.5),我正在通过 scl 实用程序运行 7.2.1,它将 /opt/rh/devtoolset-7/root/usr/bin/gcc进入路径。预计必要的库可能与 gcc 一起提供,我查看了 /opt/rh/devtoolset-7 ...就像一个噩梦一样, libatomic.a 又是一个不存在的文件的符号链接(symbolic link)。
> l `find /opt/rh/devtoolset-7/ -name '*atomic*'`
:
(headers elided)
:
-rw-r--r-- 1 root root 40975 Aug 31 2017 /opt/rh/devtoolset-7/root/usr/include/c++/7/atomic
-rw-r--r-- 1 root root 80 Aug 31 2017 /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/32/libatomic.so
-rw-r--r-- 1 root root 1553 Oct 6 2017 /opt/rh/devtoolset-7/root/usr/share/systemtap/tapset/linux/atomic.stp
lrwxrwxrwx 1 root root 40 Jul 3 2018 /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/32/libatomic.a -> ../../../i686-redhat-linux/7/libatomic.a

所以使用 -L根据 find 我能想到的每条路径的选项发现,这里是所有的错误:
> g++ MsgQueueNoLock.cxx -g -o MsgQueueNoLock -pthread -latomic
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: cannot find -latomic
collect2: error: ld returned 1 exit status
> g++ MsgQueueNoLock.cxx -g -o MsgQueueNoLock -pthread -L/usr/lib/gcc/x86_64-redhat-linux/4.8.2 -latomic
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: cannot find /usr/lib64/libatomic.so.1.0.0
collect2: error: ld returned 1 exit status
> g++ MsgQueueNoLock.cxx -g -o MsgQueueNoLock -pthread -L/usr/lib/gcc/x86_64-redhat-linux/4.8.2/32 -latomic
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: cannot find /usr/lib/libatomic.so.1.0.0
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.8.2/32/libstdc++.so when searching for -lstdc++
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.8.2/32/libgcc_s.so when searching for -lgcc_s
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.8.2/32/libgcc.a when searching for libgcc.a
collect2: error: ld returned 1 exit status
> g++ MsgQueueNoLock.cxx -g -o MsgQueueNoLock -pthread -L/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/32 -latomic
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: skipping incompatible /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/32/libatomic.so when searching for -latomic
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: cannot find -latomic
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: skipping incompatible /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/32/libstdc++.so when searching for -lstdc++
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: skipping incompatible /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/32/libgcc_s.so when searching for -lgcc_s
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: skipping incompatible /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/32/libgcc.a when searching for libgcc.a
collect2: error: ld returned 1 exit status

最佳答案

要在 gcc 中使用 16 字节原子,您需要 -latomic

关于c++ - 红帽 : using <atomic> compiles fine but linker can't find __atomic_store_16; what library?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59641984/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com