Forums: 公開討議 (Thread #22525)

once.h でmultiple definition (2009-04-27 00:34 by akira #43446)

複数の.cppファイルでthread.hをincludeしているとmultiple definition の
リンクエラーになります。
/tmp/ccIiR5ho.o:(.data+0x0): multiple definition of `clx::detail::once_global_epoch'
/tmp/ccHB39Ej.o:(.data+0x0): first defined here


スマートな解決方法は無いでしょうか?
とりあえず#ifdefで初期化は特定のファイルだけにして他はexternにしましたが
まちがっているような気もするので正しいのかもお教えください。

#ifdef MAINFILE
  once_flag once_global_epoch = ULONG_MAX;
:       
#else
extern once_flag once_global_epoch;
:
#endif

Reply to #43446×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: once.h でmultiple definition (2009-04-28 18:32 by cielquis #43516)

報告ありがとうございます.
取りあえずの対処法としては,上記で良いと思います.

修正法に関しては,現在検討中です.
修正版がリリースでき次第またこのスレッドに報告いたします.
それまでは,不便をおかけしますが上記の方法で対処をお願いいたします.
Reply to #43446

Reply to #43516×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: once.h でmultiple definition (2009-06-01 16:01 by cielquis #44127)

version 0.15.0 にて対応しました.
何か不都合がありましたら,またよろしくお願いいたします.
Reply to #43516

Reply to #44127×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: once.h でmultiple definition (2009-06-03 11:42 by akira #44160)

改修ありがとうございます。

ですが、
clx/unix/once.h:59: error: expected primary-expression before ‘{’ token
clx/unix/once.h:60: error: expected primary-expression before ‘{’ token
のエラーが出ます。
Reply to #44127

Reply to #44160×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: once.h でmultiple definition (2009-06-03 12:05 by cielquis #44162)

報告ありがとうございます & ご不便おかけしています.
上記ですが,どの環境だとエラーが出るのかが分からないので,
申し訳ありませんが,コンパイル環境(OS とコンパイラのバージョン)
を教えて頂けないでしょうか.
Reply to #44160

Reply to #44162×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: once.h でmultiple definition (2009-06-03 15:37 by akira #44172)

OSはLinux
ubuntu server v9.04

$ g++ example_thread.cpp
In file included from clx/thread.h:54,
from example_thread.cpp:36:
clx/unix/once.h: In constructor ‘clx::detail::global_condition::global_condition()’:
clx/unix/once.h:59: error: expected primary-expression before ‘{’ token
clx/unix/once.h:60: error: expected primary-expression before ‘{’ token

$ uname -a
Linux dev 2.6.28-11-server #42-Ubuntu SMP Fri Apr 17 02:48:10 UTC 2009 i686 GNU/Linux

$ gcc --version
gcc (Ubuntu 4.3.3-5ubuntu4) 4.3.3
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$
です。
Reply to #44162

Reply to #44172×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: once.h でmultiple definition (2009-06-03 13:16 by cielquis #44169)

予想される範囲で,unix/once.h を修正してみました.
最新のソースコード (unix/once.h) は下記から取得できます.
http://svn.sourceforge.jp/view/trunk/unix/?root=clxcpp
よろしければ,試した結果を知らせて頂けると幸いです.
Reply to #44160

Reply to #44169×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: once.h でmultiple definition (2009-06-03 15:50 by akira #44173)

お世話になっています。

http://svn.sourceforge.jp/view/trunk/unix/?root=clxcpp
このonce.hに入れ替えるとコンパイルエラーは起こらなくなりました
$ g++ example_thread.cpp -lpthread
$ ./a.out
AAAAA
AAAAAA
AAAAAAA
AAAAAAAA
AAAAAAAAA
AAAAAAAAAA
AAAAAAAAAAA
AAAAAAAAAAAA
AAAAAAAAAAAAA
AAAAAAAAAAAAAA
BBBBB
BBBBBB
BBBBBBB
BBBBBBBB
BBBBBBBBB
BBBBBBBBBB
BBBBBBBBBBB
BBBBBBBBBBBB
BBBBBBBBBBBBB
BBBBBBBBBBBBBB

end of main thread
$
Reply to #44169

Reply to #44173×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login