Hi,
I have been investigating a problem I have while building Qt-embedded
with GCC-4.5.0 for ARM/Linux, and managed to produce the reduced test
case as follows.
Consider this shared library (C++):
==================================== atomic.cxx
int atomicIncrement(int volatile* addend)
{ return __sync_fetch_and_add(addend, 1) + 1; }
====================================
Compiled with:
$ arm-linux-g++ atomic.cxx -fPIC -shared -o libatomic.so
Now the main program:
==================================== atomain.cxx
extern int atomicIncrement(int volatile* addend);
volatile int myvar;
int main()
{ return atomicIncrement(&myvar); }
====================================
Compiled & linked with:
$ arm-linux-g++ atomain.cxx -o atomain -L. -latomic
.../ld: atomain: hidden symbol `__sync_fetch_and_add_4' in
/.../libgcc.a(linux-atomic.o) is referenced by DSO
What I have found is that g++ (unlike gcc) links with -lgcc_s instead of
-lgcc and that the atomic functions are present in libgcc.a and not in
libgcc_s.so.
If I create libatomic.so with -lgcc, it works.
What I don't understand is if this is the intended behaviour and that
adding -lgcc is the right fix, or not?
[This surprises me, because as I said, I faced this problem when
compiling Qt-embedded for ARM/Linux and I don't think I am the only one
doing that, so I expected it to just work ;-)]
Thanks,
Christophe.