GCC command line parameter problems (static library, 32/64 bit, pthread)

Source: Internet
Author: User

Since GCC parameters are completely unknown, I wasted more than an hour this morning. "Pay homage to the lost time in this article"

1. Generate a static Link Library:
Two steps
G ++-c aaa. cpp
Ar-SSP libaaa. a aaa. o
By default, gcc requires that the library file name must be in the form of lib [name]. a. The dynamic link library is similar to. so.

2. There are two ways to use libaaa..
G ++ main. c-L "PATH_TO_AAA"-laaa
Or
G ++ main. c libaaa.
The former is common when using static databases. The most important thing is that the-L and-l parameters must be specified after the source file! I did not know this problem today. I tried it for a long time. I guess this rule helps to specify different libraries for different source files, which is clearer.

3. 64-bit system parameters-m64
How can we see if our system is 64-bit?
$ Su-root
# File/sbin/init
/Sbin/init: ELF <B>; 32-bit </B>; LSB executable, Intel 80386 ......
Literally, this is the right one.

4. Linux thread Library
POSIX standard thread library pthread. If the multi-threaded library is used in the project, pay attention to the gcc parameters. Sometimes-lpthread will fail, such as RakNet.-pthread must be used at this time.
-The difference between pthread and-lpthread can be found on the Internet.

$ Gcc-v-c x. c
...
/Usr/lib/gcc/i486-linux-gnu/4.2.4/PC3-quiet-v x. c-quiet-dumpbase x. c

$ Gcc-v-pthread-c x. c
...
/Usr/lib/gcc/i486-linux-gnu/4.2.4/PC3-quiet-v-D_REENTRANT

It can be seen that specifying-pthread in the compilation option will append a macro definition-D_REENTRANT, which will lead to the libc header file to select the thread-safe implementation; specifying-pthread in the Link option is the same as-lpthread, only links the POSIX thread library. Because libc is used to adapt to the possible changes in macro definitions of thread-safe, the-pthread option is used during compilation and linking, rather than the traditional-lpthread, to maintain backward compatibility and improve command line consistency.


From Good Orcs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.