您的位置:首页 > 其它

How to solve the linking errors when using the ATOMIC functions

2009-03-13 19:14 639 查看
[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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐