2013-07-17 11 views
5

アトミックのis_lock_free()メソッドを使用しようとすると、次のコンパイルエラーが発生しました。mingw-4.8.1原子の問題

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()大丈夫ですとatomic<builtin>::is_lock_free()builtinはfondamentalタイプである場合には、うまく動作します。

しかしis_lock_freeの呼び出しS3のためには、リンクエラーを与える:undefined reference to __atomic_is_lock_free

は、私はいくつかの外部ライブラリをリンクする必要がありますか?私に何ができる?

編集1

同じ問題がUbuntuの13.04

にgcc4.8.1で発生COMANDラインオプションは次のとおりです。

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 

編集2

gccに-latomicと-lpthreadを追加しましたが、同じエラーが発生しました:

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は、私のシステムに存在している:

$ 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 

答えて

7

あなたは(GCCによって提供される)libatomicとリンクする必要があります。

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

はまだ –

+1

動作しないこととすることができます私の誤り:コマンドラインで '.o'の前に' -latomic'を動かしてみて、私の答えを更新できるように動作しているかどうかを教えてください。 – syam

+0

同じ結果がない: 'g ++ -c -pipe -std = C++ 11 -lpthread -g -Wall -W -fPIE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -I ../../../../ Qt/5.1。 0/gcc_64/mkspecs/linux-g ++ -I ../atomic -I。 -o main.o ../ atomic/main.cpp' 'g ++ -latomic -lpthread -Wl、-rpath、/ home/dmdtek/Qt/5.1.0/gcc_64 -o原子main.o' –