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