未定义的引用`__sync_val_compare_and_swap_4'的编译错误,使用gcc 4.1.1和4.2.0的SPARC V8目标 [英] 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
问题描述
使用的crosstool 的剧本我已经下的 Cygwin的的下列编译器GCC-4.1.1和4.2.0 20061024($ p $租赁前)为SPARC架构:
Using crosstool scripts i've built under Cygwin the following compilers gcc-4.1.1 and 4.2.0 20061024 (prerelease) for Sparc architecture:
$ ./sparc-unknown-linux-gnu-gcc -v
Using built-in specs.
Target: sparc-unknown-linux-gnu
Configured with: /crosstool-0.43/build/sparc-unknown-linux-gnu/gcc-4.1.1-glibc-2.3.6/gcc-4.1.1/configure --target=sparc-unknown-linux-gnu --host=i686-host_pc-cygwin --prefix=/opt/crosstool/gcc-4.1.1-glibc-2.3.6/sparc-unknown-linux-gnu --with-headers=/opt/crosstool/gcc-4.1.1-glibc-2.3.6/sparc-unknown-linux-gnu/sparc-unknown-linux-gnu/include --with-local-prefix=/opt/crosstool/gcc-4.1.1-glibc-2.3.6/sparc-unknown-linux-gnu/sparc-unknown-linux-gnu --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atexit --enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long
Thread model: posix
gcc version 4.1.1
和
$ ./sparc-unknown-linux-gnu-gcc -v
Using built-in specs.
Target: sparc-unknown-linux-gnu
Configured with: /crosstool-0.43/build/sparc-unknown-linux-gnu/gcc-4.2-20061024- glibc-2.3.6/gcc-4.2-20061024/configure --target=sparc-unknown-linux-gnu --host=i 686-host_pc-cygwin --prefix=/opt/crosstool/gcc-4.2-20061024-glibc-2.3.6/sparc-un known-linux-gnu --with-headers=/opt/crosstool/gcc-4.2-20061024-glibc-2.3.6/sparc -unknown-linux-gnu/sparc-unknown-linux-gnu/include --with-local-prefix=/opt/cros stool/gcc-4.2-20061024-glibc-2.3.6/sparc-unknown-linux-gnu/sparc-unknown-linux-g nu --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atex it --enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long
Thread model: posix
gcc version 4.2.0 20061024 (prerelease)
这是必要的我,我可以在我的程序中使用相关的 __ sync_val_compare_and_swap 功能GCC-4.1.2 / GCC /原子Builtins.html相对=nofollow>原子内建命令,支持蒙山4.1。*的gcc版本。
It is necessary for me that i can use in my programs __sync_val_compare_and_swap
function related to the Atomic-Builtins, which supports whith 4.1.* version of gcc.
我尝试编译简单的C code:
I try to compile simple C code:
long cmpxchg( long* value, long comp_val, long new_val )
{
return __sync_val_compare_and_swap( value, comp_val, new_val );
}
int main()
{
return 0;
}
但我有以下错误:(在两种编译器):
But i have the following error: (on both compilers):
$ ./sparc-unknown-linux-gnu-gcc test_cas.c -o test_cas
/tmp/ccREXHsP.o: In function `cmpxchg':
test_cas.c:(.text+0x24): undefined reference to `__sync_val_compare_and_swap_4'
collect2: ld returned 1 exit status
这是什么问题?可能是我错了内置的编译器?可能是SPARC架构(SPARC V8)不支持这个功能吗?我试图编译我的另一个项目 - 都好(编译和执行)
What's the problem? May be i wrong built compilers? May be Sparc architecture (SPARC v8) doesn't support this feature? I tried to compile my another programs - all good (compiled and executed).
推荐答案
如下所述:<一href=\"http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html\">http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html __ sync_val_compare_and_swap
在某些目标将导致一个函数调用(其中直接code一代不可用或尚未执行)。这是发生在你的情况。假设本身是不是你一个问题,你这时就需要定义 __ sync_val_compare_and_swap_4
和朋友库,我猜是的libgcc_s (所以 -lgcc_s
添加到您的链接线)。
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).
这篇关于未定义的引用`__sync_val_compare_and_swap_4'的编译错误,使用gcc 4.1.1和4.2.0的SPARC V8目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!