How to solve the linking errors when using the ATOMIC functions

本文介绍了解决在i386平台上使用GCC提供的新原子函数时出现的链接错误的方法。通过使用特定的编译选项,如`-march=i486`,可以成功编译包含原子操作的源代码。

 

[How to solve the linking errors when using the ATOMIC functions?]

When some new atomic functions of GCC are used in the i386 platform, the linking errors maybe take place. It takes me troubles in some time even if I have updated GCC to the latest version (GCC-4.3.3). Herein, I will give my solution to overcome it, and share the experience with you in the Linux OS.

 

[How to know whether your machine is i386?]

Please use ‘uname’ command to disclose your hardware platform.

$ uname -i

i386

 

[What are the atomic functions?]

1. __sync_add_and_fetch()

2. __sync_sub_and_fetch()

3. __sync_lock_test_and_set()

4. __sync_add_and_fetch()

 

[How to compile your source codes in the i386?]

It is a critical stage to get rid of the linking errors. Maybe you have known, these functions are provided by GCC (Not glibc), so the special compiling option must be added at the compile step. For example:

gcc -o atomic.o -c -fvisibility=hidden -march=i486 -Wall -pthread -O3 -fPIC atomic.c

Do you find the RED-BOLD part? Yes, it is a key option! If you have met troubles to link these files using atomic functions, please confirm whether ‘-march=i486’ has been added.

 

After compiling, are you happy? I guess that it is true! Haha!.

 

[Summarization]

Open-Source is a big platform including huge information/tools…, so the accumulation plays very important role in the daily activities. The trivial points of knowledge should be tidied when you have spent much time in finding the root causes. Meanwhile, if it can help freshmen touching this field, its value is represented.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值