undefined reference to `__sync_val_compare_and_swap_4' error at compilation, using gcc 4.1.1 and 4.2.0 for Sparc v8 target

风流意气都作罢 提交于 2019-11-28 14:05:00
John Zwinck

As described here: http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html __sync_val_compare_and_swap on some targets will result in a function call (where direct code generation is not available or not yet implemented). That is happening in your case. Assuming that itself is not a problem for you, you then need to link the library which defines __sync_val_compare_and_swap_4 and friends, which I am guessing is libgcc_s (so add -lgcc_s to your link line).

It looks like there's a related gcc bug:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40134

Maybe try a newer gcc?

I came across a similar problem when compiling NodeJS(which based on V8 engine) on ARMv5 platform.

Basically speaking, your GCC does not have this build-in functions, either because you are using an old version, or these functions are not implemented on your platform yet,so the "-lgcc_s" may even not help.

After Google for hours, I found this blog page( http://vincesoft.blogspot.fr/2012/04/how-to-solve-undefined-reference-to.html ), which explain the cause fairly clear and gave a solution:

Grab the source code of your platform with these functions from GCC code, build the code into a library, install it, and then link your applications against this library.

I did not follow the exact procedures described in this blog, but the idea is the same, and it works.

Hope it helps.

on Android I was able to solve the issue with the following flags LOCAL_CFLAGS += -O3 -fopenmp LOCAL_LDFLAGS += -O3 -fopenmp -lgcc -latomic -lgomp

rogerdpack

For me, the above failure meant "you are using a gcc/mingw cross compiler, so -march=native doesn't work" (I guess). See https://stackoverflow.com/a/24213278/32453 (basically you can work around it by manually specifying the -march setting).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!