std ::原子库依赖(gcc 4.7.3) [英] std::atomic library dependency (gcc 4.7.3)

查看:355
本文介绍了std ::原子库依赖(gcc 4.7.3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用std :: atomic编译,我得到未解析的引用__atomic_load,__atomic_store和__atomic_store_16。



我知道在更新版本的gcc(4.8+?)中包括-latomic,但是我正在使用gcc 4.7.3编译;我已经尝试添加-latomic_ops和-latomic_ops_gpl,但似乎没有多少。



我现在安装gcc 4.8.1,但我有一个发布平台非常感谢。



编辑:



$ b好吧,这里有一些代码导致的问题我有:

  atomics.cpp 
#include< atomic> ;
#include< stdint.h>

struct dataStruct {
int a;
uint16_t b;
float c;
dataStruct(int ai,uint16_t bi,float ci)noexcept:a(ai),b(bi),c(ci){
}
dataStruct 0,0){
}
};

int main(){
std :: atomic< dataStruct> atomicValue;

atomicValue = dataStruct(10,0,0);

return atomicValue.load()。b;
}

使用g ++ - 4.8.1 * .cpp -std = c ++



使用g ++ - 4.7.3 * .cpp -std = c ++ 0x -pthread -lpthread -latomic_ops失败,以下内容:

  /tmp/ccQp8MJ2.o:在函数'的std ::原子< dataStruct> ::负载(的std :: memory_order)常量:
atomics.cpp :( text._ZNKSt6atomicI10dataStructE4loadESt12memory_order [_ZNKSt6atomicI10dataStructE4loadESt12memory_order] +值为0x2F):未定义的参考`__atomic_load'
/tmp/ccQp8MJ2.o:在函数'标准: :原子< dataStruct> ::店(dataStruct,性病:: memory_order):
atomics.cpp :( text._ZNSt6atomicI10dataStructE5storeES0_St12memory_order [_ZNSt6atomicI10dataStructE5storeES0_St12memory_order] + 0x35):未定义的参考`__atomic_store'
collect2:错误:LD返回1退出状态


解决方案

好吧,终于找到了答案在: https://gcc.gnu.org/wiki/Atomic/GCCMM



原来,4.7并没有实际上有'官方'原子公司的支持(只是头文件)。如果你想在4.7编译器使用原子能,您必须下载该网页上链接的源代码,并建立它自己

  GCC  - c -o libatomic.o libatomic.c 
ar rcs libatomic.a libatomic.o

然后,你可以用它建立

  G ++  -  4.7.3 -std =的C ++ 0x atomics.cpp -latomic -L ./ 


I've been trying to compile with std::atomic, and I'm getting unresolved references to __atomic_load, __atomic_store, and __atomic_store_16.

I know in a later version of gcc (4.8+?) you include -latomic, but I'm compiling with gcc 4.7.3; I've tried adding -latomic_ops and -latomic_ops_gpl, but neither seem to do much.

I am installing gcc 4.8.1 now, but I do have a release platform that'll really need to be compiled for 4.7.3.

Many thanks.

Edit: Ok, here's some code that results in the problem I have:

atomics.cpp
#include <atomic>
#include <stdint.h>

struct dataStruct {
    int a;
    uint16_t b;
    float c;
    dataStruct(int ai, uint16_t bi, float ci)  noexcept : a(ai), b(bi), c(ci) {
    }
    dataStruct() noexcept : dataStruct(0,0,0) {
    }
};

int main() {
    std::atomic<dataStruct> atomicValue;

    atomicValue = dataStruct(10, 0, 0);

    return atomicValue.load().b;
}

With "g++-4.8.1 *.cpp -std=c++0x -latomic", this compiles fine.

With "g++-4.7.3 *.cpp -std=c++0x -pthread -lpthread -latomic_ops", it fails with the following:

/tmp/ccQp8MJ2.o: In function `std::atomic<dataStruct>::load(std::memory_order) const':
atomics.cpp:(.text._ZNKSt6atomicI10dataStructE4loadESt12memory_order[_ZNKSt6atomicI10dataStructE4loadESt12memory_order]+0x2f): undefined reference to `__atomic_load'
/tmp/ccQp8MJ2.o: In function `std::atomic<dataStruct>::store(dataStruct, std::memory_order)':
atomics.cpp:(.text._ZNSt6atomicI10dataStructE5storeES0_St12memory_order[_ZNSt6atomicI10dataStructE5storeES0_St12memory_order]+0x35): undefined reference to `__atomic_store'
collect2: error: ld returned 1 exit status

解决方案

Ok, finally found the answer at: https://gcc.gnu.org/wiki/Atomic/GCCMM

Turns out, 4.7 did not in fact have 'official' atomics support (just the header files). If you want to use atomics in 4.7 compilers, you must download the source code linked on that page and build it yourself

gcc -c -o libatomic.o libatomic.c
ar rcs libatomic.a libatomic.o

Then, you can build it using

g++-4.7.3 -std=c++0x atomics.cpp -latomic -L./

这篇关于std ::原子库依赖(gcc 4.7.3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆