TwitterTwitter FacebookFacebook FlickrFlickr RSSRSS

20100511

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

[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.

<!--[if !supportEmptyParas]--> <!--[endif]-->

[How to know whether your machine is i386?]

Please use 'uname' command to disclose your hardware platform.

$ uname -i

i386

<!--[if !supportEmptyParas]--> <!--[endif]-->

[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()

<!--[if !supportEmptyParas]--> <!--[endif]-->

[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.

<!--[if !supportEmptyParas]--> <!--[endif]-->

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

<!--[if !supportEmptyParas]--> <!--[endif]-->

[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.

<!--[if !supportEmptyParas]--> <!--[endif]-->

 
PUMA螢光夜跑