mingw-4.8.1原子问题 [英] mingw-4.8.1 atomic issue

查看:1636
本文介绍了mingw-4.8.1原子问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用原子的is_lock_free()方法时,我有以下编译错误。

  struct Simple1 { int i; }; 
struct Simple2 {int a; int b; };
struct Simple3 {int a; int b; int c; };

int main()
{
atomic<计数器>计数器;
atomic<参数>帕拉姆
atomic<简单1> s1;
atomic< Simple2> s2;
atomic< Simple3> s3;

cout
<< s1 lock free?<< boolalpha< s1.is_lock_free()<< '\\\
'
<< s2 lock free?<< boolalpha< s2.is_lock_free()<< '\\\
'
<< s3 lock free?<< boolalpha< s3.is_lock_free()<< '\\\
';
}

s1.is_lock_free()和s2.is_lock_free )可以和 atomic< builtin> :: is_lock_free(),其中内置是一个基本类型,工作正常。



但是对于s3, is_lock_free 的调用会产生链接错误:未定义引用__atomic_is_lock_free



我需要链接一些外部库吗?我可以做什么?



编辑1



.8.1在Ubuntu 13.04上



comand行选项如下:

  g ++ -O0 -g3 -Wall -c -fmessage-length = 0 -std = c ++ 11 -oatomic_test.oatomic_test.cpp
g ++ -std = c ++ 11 -o hello.exe atomic_test.o

编辑2
$ b

我在gcc上添加了-latomic和-lpthread,但我也有同样的错误:

  04:09:37:运行步骤为项目原子... 
04:09:37:配置不变,跳过qmake步骤。
04:09:37:Starting:/ usr / bin / make
/home/dmdtek/Qt/5.1.0/gcc_64/bin/qmake -spec linux-g ++ CONFIG + = debug CONFIG + = declarative_debug CONFIG + = qml_debug -o Makefile ../atomic/atomic.pro
g ++ -latomic -lpthread -Wl,-rpath,/ home / dmdtek / Qt / 5.1.0 / gcc_64 -o atomic main.o
main.o:in function`std :: atomic< Simple3> :: is_lock_free()const':
/usr/include/c++/4.8/atomic:191:undefined reference to`__atomic_is_lock_free'
main.o:在函数`std :: atomic< long double> :: is_lock_free()const':
/usr/include/c++/4.8/atomic:191:未定义引用`__atomic_is_lock_free'
collect2:错误:ld返回1退出状态
make:*** [atomic]错误1
04:09:37:进程/ usr / bin / make退出代码2.
构建/部署项目时出错(kit:Desktop Qt 5.1.0 GCC 64位)
执行步骤'Make'
04:09:37:经过时间:00:00。

libatomic存在于我的系统上:

  $ ldconfig -v | grep atomic 
/sbin/ldconfig.real:Path`/ lib / x86_64-linux-gnu'给出多次
/sbin/ldconfig.real:Path`/ usr / lib / x86_64-linux- gnu'给定多次
libatomic.so.1 - > libatomic.so.1.0.0
/sbin/ldconfig.real:无法创建临时缓存文件/etc/ld.so.cache〜:Permission denied


解决方案

您需要链接到 libatomic GCC):

  g ++ -std = c ++ 11 -o hello.exe atomic_test.o -latomic 


I've the following compile error when I try to use the method is_lock_free() of atomic.

struct Simple1 { int i; };
struct Simple2 { int a; int b; };
struct Simple3 { int a; int b; int c; };

int main()
{
    atomic< Counter > counter;
    atomic< Param > param;
    atomic< Simple1 > s1;
    atomic< Simple2 > s2;
    atomic< Simple3 > s3;

    cout
        << "Is s1 lock free? " << boolalpha << s1.is_lock_free() << '\n'
        << "Is s2 lock free? " << boolalpha << s2.is_lock_free() << '\n'
        << "Is s3 lock free? " << boolalpha << s3.is_lock_free() << '\n';
   }

s1.is_lock_free() and s2.is_lock_free() are okay and atomic< builtin >::is_lock_free(), where builtin is a fondamental type, works well.

But for s3 the call of is_lock_free gives a linkage error: undefined reference to __atomic_is_lock_free

Does I need to link some external library? What can I do?

Edit 1

The same issue occur on gcc4.8.1 on Ubuntu 13.04

The comand line option is the following:

g++ -O0 -g3 -Wall -c -fmessage-length=0 -std=c++11 -o "atomic_test.o" "atomic_test.cpp" 
g++ -std=c++11 -o hello.exe atomic_test.o

Edit 2

I added -latomic and -lpthread on gcc but I've the same error:

04:09:37: Running steps for project atomic...
04:09:37: Configuration unchanged, skipping qmake step.
04:09:37: Starting: "/usr/bin/make" 
/home/dmdtek/Qt/5.1.0/gcc_64/bin/qmake -spec linux-g++ CONFIG+=debug      CONFIG+=declarative_debug CONFIG+=qml_debug -o Makefile ../atomic/atomic.pro
g++ -latomic -lpthread -Wl,-rpath,/home/dmdtek/Qt/5.1.0/gcc_64 -o atomic main.o    
main.o: In function `std::atomic<Simple3>::is_lock_free() const':
/usr/include/c++/4.8/atomic:191: undefined reference to `__atomic_is_lock_free'
main.o: In function `std::atomic<long double>::is_lock_free() const':
/usr/include/c++/4.8/atomic:191: undefined reference to `__atomic_is_lock_free'
collect2: error: ld returned 1 exit status
make: *** [atomic] Error 1
04:09:37: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project atomic (kit: Desktop Qt 5.1.0 GCC 64bit)
When executing step 'Make'
04:09:37: Elapsed time: 00:00.

libatomic is present on my system:

$ ldconfig -v | grep atomic
/sbin/ldconfig.real: Path `/lib/x86_64-linux-gnu' given more than once
/sbin/ldconfig.real: Path `/usr/lib/x86_64-linux-gnu' given more than once
libatomic.so.1 -> libatomic.so.1.0.0
/sbin/ldconfig.real: Can't create temporary cache file /etc/ld.so.cache~: Permission denied

解决方案

You need to link with libatomic (which is provided by GCC):

g++ -std=c++11 -o hello.exe atomic_test.o -latomic

这篇关于mingw-4.8.1原子问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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