每当我尝试在64位计算机上使用带有-m32的 __ sync_fetch_and_add 时,我会收到以下错误,而正常的64位编译正常。我正在使用gcc编译器4.1.2。这可能是什么问题,解决方案是什么?
replication.cpp:(.text+0xb3b): undefined reference to `__sync_fetch_and_add_4'
replication.cpp:(.text+0xb82): undefined reference to `__sync_fetch_and_add_4'
replication.cpp:(.text+0xcc2): undefined reference to `__sync_fetch_and_add_4'
/tmp/cc7u9FLV.o: In function `potential_barrier_leader(unsigned int, pthread_barrier_t*)':
replication.cpp:(.text+0xd3f): undefined reference to `__sync_fetch_and_add_4'
replication.cpp:(.text+0xd54): undefined reference to `__sync_fetch_and_add_4'
/tmp/cc7u9FLV.o:replication.cpp:(.text+0xdb0): more undefined references to `__sync_fetch_and_add_4' follow
collect2: ld returned 1 exit status
make: *** [all] Error 1
答案 0 :(得分:7)
使用 -march = i486 标志为我做了诀窍。
答案 1 :(得分:1)
尝试使用更新的GCC编译器(例如GCC 4.6)。我尝试使用gcc -S -O3 -m32 -fverbose-asm sync-3.c
编译测试文件gcc/testsuite/gcc.c-torture/compile/sync-3.c
并且它可以正常工作。我的gcc
(在Debian / Sid / AMD64上)是系统gcc 4.6.2编译器。
答案 2 :(得分:1)
HAHAH!有5个以上的“标准原子库”(+内核支持),它几乎不是原子 如果你问我我。但是忽略它,是一种及时的分心。
所以你的建筑,即glibc并得到那个错误(我做了)
glibc-2.11.x期望gcc-4.4.x在内部定义它,你有gcc sans bu ilt-in atomic,你可能没有指定gcc接受的arch(由于缺乏可怕性) ctions)。 glibc喜欢786,gcc想要386和786或许。用“nativ e“应该这样做。选择(行军)和选择(mtune)是非可选的gcc构建错误w / 他们(可能)
你找不到定义它的标题或libfoo(按照说法)
对于linux-gnu你可以使用(简单的moi构建)
cd gcc-4.4.foo
./configure --with-glibc-version=2.11 --enable-threads=posix \
--disable-cloog --disable-ppl --disable-libssp --enable-__cxa_atexit \
--disable-rpath --disable-nls --disable-bootstrp --disable-multilib \
--with-system-libunwind
重要提示:如果您构建gcc w / o mtune march right,gcc将不会定义sync_fetch_and_add (p.s. glibc sync_fetch_and_add_4只是sync_fetch_and_add的宏,aga 在,glibc期望定义)
如果你用gcc-4.4.foo替换gcc-3.foo并且正在编译你可能需要:
[ -n "$newgnu" ] && CFLAGS="$CFLAGS -march=native -mtune=native "
[ -n "$newgnu" ] && \
CFLAGS="$CFLAGS -std=gnu89 " && CPPFLAGS="$CPPFLAGS -std=gnu89 "
我新需要这个(newgnu)来构建binutils-ver /: - Wstrict-aliasing = 0
cd glibc-2.foo/
./configure --with-headers=/usr/src/linux/usr/include \
--enable-kernel=2.2.foo \
--disable-profile --disable-sanity-checks --with-tls \
--disable-rpath --disable-nls
感谢荷兰人发帖 - 这可能是gcc升级者的问题!
不,谢谢被委员会不断变化,并创建“标准”,这取决于gcc中的问题:(使用.h或.c适当地为foo“builtin”添加你想要的功能,就像其他人一样! !
玩得开心:)