GCC Force link Static Library

Source: Internet
Author: User
Tags naming convention

Keywords: linux; gcc; compile; link;

one. Compile and Link options:
First step: precompiling.
GCC-E Hello.c-o hello.i
-e parameter: GCC stops the compilation process after the preprocessing is complete.
The preprocessed macro definition expands into the hello.i.

Step two: Generate the target code.
Gcc-c Hello.i-o hello.o
-C parameter: Generate target code.
Compile the HELLO.I as the target code, or it can be generated directly from the source file.
Gcc-c hello.c

Step three: Link.
GCC Hello.o-o Hello
Link the generated target file into an executable file.
Can also be generated directly from the source file.
Gcc-o Hello hello.c

two. To set warning options:
1,-pedantic option: Use the extension syntax where the corresponding warning message will be generated
2.-wall option: Requires GCC to generate as many warning messages as possible
3.-werror option: Require GCC to treat all warnings as errors

three. Library Dependencies Options:
1. Linux bottom file and library file default directory:
Header file (. h):/usr/include/directory
library file (. So,. A):/usr/lib/directory

2. Common options:
-I option: Adds a new directory to GCC's header file search path.
Gcc-o Hello hello.c-i/home/crosstar/include
GCC is required to find the required header files under the/home/crosstar/include/directory.

-L Option: Adds a new directory to GCC's library file search path.
Gcc-o Test Test.c-l/home/crosstar/lib–lfoo
GCC is required to look for the required library files under the/home/crosstar/lib/directory libfoo.so

-L option: Requires GCC link library file libfoo.so.
Note: The library file naming convention under Linux:
Usually begins with a Lib three letter.
Because all library files follow the same specification, you can omit Lib three letters when you specify a linked library file name with the-l option, which means that GCC automatically links files named libfoo.so when processing-lfoo.

-static option: Force the use of static link libraries
Gcc-o Test Test.c-l/home/crosstar/lib-static–lfoo
Request GCC links when statically linked to the/home/crosstar/lib/directory LIBFOO.A

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.