How to solve the "undefined reference to '__sync_sub_and_fetch_4'" compilation problem
来源:互联网 发布:nike旗舰店淘宝 编辑:程序博客网 时间:2024/05/23 13:02
这个问题的有时候是gcc版本不对的原因导致的,因为他需要低版本的gcc工具链。
If you ran into the following compilation problems:
undefined reference to '__sync_sub_and_fetch_4' problemor with any of the following functions:
__sync_fetch_and_add, __sync_fetch_and_sub, __sync_fetch_and_or, __sync_fetch_and_and, __sync_fetch_and_xor, __sync_fetch_and_nand, __sync_add_and_fetch, __sync_sub_and_fetch, __sync_sub_or_fetch, __sync_and_and_fetch, __sync_xor_and_fetch, __sync_nand_and_fetch__sync_val_compare_and_swap, __sync_bool_compare_and_swap, __sync_lock_test_and_set,__sync_lock_release
Chances are that you are trying to compile for ARM (or an exotic architecture) and your GCC version is too old compared to the source code you are trying to compile!
There is an Easy fix: upgrade your GCC.
If you can't upgrade your GCC for any reason (for example you are on an embedded hardware you don't have full control on), follow the steps below!
1. Find the source code file that's right for the architecture you are trying to compile on
You are going to find it inside a GCC source tarball.
To find it, go into your gcc source gcc/config and do
grep '__sync_fetch' */*to find the right file.
For ARM, it is:
gcc/config/arm/linux-atomic.c
2. Compile the source code file and link in to the program you are compiling
libtool --tag=CC -mode=compile gcc -g -O2 -MT linux-atomic.lo -MD -MP -MF linux-atomic.Tpo -c -o linux-atmoic.lo linux-atmoic.clibtool --tag=CC -mode=link gcc -g -O2 -o liblinux-atmoic.la linux-atmoic.loAnd add liblinux-atomic.la in the Makefile so it is linked to the other .la files (into a .so or a program).
3. Example to compile libtorrent 13.1 and rtorrent 0.9.1 for ARM with GCC 4.2.3
If you wonder, this is to compile rtorrent for my Iomega ix4-200d storcenter NAS.
Compile libtorrent:
PATH=$PATH:/opt/binwget http://libtorrent.rakshasa.no/downloads/libtorrent-0.13.1.tar.gztar -xvf libtorrent-0.13.1.tar.gzcd libtorrent-0.13.1vi configureOPENSSL_CFLAGS='-I/opt/include/'OPENSSL_LIBS='-L/opt/lib/ -lssl'STUFF_LIBS='-L/opt/lib/ -lsigc-2.0'STUFF_CFLAGS='-I/opt/usr/include/sigc++-2.0/ -I/opt/usr/lib/sigc++-2.0/include'./configure --prefix=/opt/
Add linux-atomic:
cd srcwget http://dl.dropbox.com/u/50398581/rtorrent-0.9.1/linux_atomic.clibtool --tag=CC --mode=compile gcc -g -O2 -MT linux_atomic.lo -MD -MP -MF linux_atomic.Tpo -c -o linux_atomic.lo linux_atomic.cvi /opt/bin/libtool
And if necessary, modify libtool for the follwoing entries:
AR="ar"RANLIB="ranlib"CC="g++"
libtool --tag=CC --mode=link gcc -g -O2 -o liblinux_atomic.la linux_atomic.lovi Makefile
add
liblinux_atomic.laat the end of libtorrent_la_LIBADD
cd ..makestrip .libs/libtorrent.somake install
Compile rtorrent:
wget http://libtorrent.rakshasa.no/downloads/rtorrent-0.9.1.tar.gztar -xvf rtorrent-0.9.1.tar.gzcd rtorrent-0.9.1vi configureAnd add:
sigc_LIBS='-L/opt/lib/ -lsigc-2.0 -L/lib/'sigc_CFLAGS='-I/opt/usr/include/sigc++-2.0/ -I/opt/usr/lib/sigc++-2.0/include -I/opt/include/ncurses'libcurl_LIBS='-L/opt/lib/ -lcurl'libcurl_CFLAGS='-I/opt/include/'libtorrent_LIBS='-L/opt/lib/ -ltorrent'libtorrent_CFLAGS='-I/opt/include/'
Then:
./configure --prefix=/opt/ --with-xmlrpc-c=/opt/bin/xmlrpc-c-config --with-ncurses=yes LDFLAGS='-L/opt/lib/' CPPFLAGS='-I/opt/include -I/opt/include/ncurses/' cd srccp ../../libtorrent-0.13.1/.libs/liblinux_atomic.a .vi Makefileat the end of rtorrent_LDADD, add
liblinux_atomic.a
Then:
makestrip rtorrentcd ..make install
You are done!
- How to solve the "undefined reference to '__sync_sub_and_fetch_4'" compilation problem
- How to solve the "undefined reference to '__sync_sub_and_fetch_4'" compilation problem
- matcaffe compilation problem: undefined reference to mxIsGPUArray
- method to solve problem of undefined reference to 'main '
- how to solve the problem we met?
- How to solve the Candy problem?
- 移植Qt-4.8.5出现undefined reference to '__sync_sub_and_fetch_4'解决方法
- 移植Qt-4.8.5出现undefined reference to '__sync_sub_and_fetch_4'
- undefined reference to symbol 'XConvertSelection' to solve
- how to solve aliasing problem
- How To Solve The Problem : Unstable Ubuntu ADSL Connection
- How to solve the issue of RSARTE's starting problem
- 移植Qt-4.8.5出现undefined reference to '__sync_sub_and_fetch_4'解决方法--转载
- caffe compilation: libopencv_highgui undefined reference to TIFF library
- java.lang.Error: Unresolved compilation problem: Cannot make a static reference to the non-static
- How to Solve a Mathematics Problem?
- how to solve a math problem
- How to solve TFS slow response problem?
- 向RichTextBox控件不停的追加数据时,如何把光标的焦点始终显示到最后
- 一些开发的技术网站网址汇总
- Windows下安装Flask
- 第八次上机报告
- cocos2d-x android eclipse环境下常见问题
- How to solve the "undefined reference to '__sync_sub_and_fetch_4'" compilation problem
- linux i2c驱动
- List<T>泛型集合 类型整体快速转换
- MAC下Android的Eclipse开发环境的搭建
- 第八次上机 任务二
- WebLogic12C安装
- ps学习点滴
- Centos vsftpd安装
- .net实例:WINFORM是实现窗体最小化到系统托盘中