undefined reference to __sync_sub_and_fetch_4 compiling with mingw
Logging Framework for C++
Brought to you by:
wilx
log4cplus release: v1.1.1-rc1
compiler: mingw32 gcc 4.7.1
OS: Windows 7 64 bit
error: undefined reference to __sync_sub_and_fetch_4 in pointer.cxx
The compilation is successful if I change
destroy = __sync_sub_and_fetch (&count, 1) == 0;
in
__sync_sub_and_fetch (&count, 1);
destroy = (count==0);
Could be OK?
The sugested change is not ok. Fetching the count variable must be atomic.
What Mingw distribution are you using? What GCC version?
I still cannot reproduce it. I am surprised that there exists a version of GCC that would not have those built-in functions available. Please try to report this as a compiler bug.
So I have been able to reproduce this by using
-march=i386
inCXXFLAGS
. You could have saved me some time by following the Bug Reporting Instruction.As long as you do not actually require executables that actually run on the actual Intel (and compatible) i386 SX/DX CPUs, you can work around it by using
-march=i486
(or higher) flag.I have fixed the breakage in log4cplus using the attached patch. However, GCC's libstdc++ is still broken as it relies on the __sync* routines internally as well:
Last edit: Václav Haisman 2013-01-04
I have reproduced this with Ruby's DevKit-tdm-32-4.5.2-20111229-1559-sfx as well. It seems that this specific TDM's GCC build is not given a '--with-arch=' switch and it defaults to i386 (on x86 platform). I am mainly using Linug-x-MinGW64 cross compiler and that has different configuration, thus this has not turned up on my builds.
I have one more patch to push. I had to add it to make things work with this DevKit (different error). I will push it later today to trunk.
I am closing this as fixed now.