Linux Environment Programming compiler tool and dynamic State Library

Source: Internet
Author: User

compiler gcc in Linux environment

Gcc:

-O compilation chain delivered as executable

-O-O1-O2-O3 Compilation optimization

-G-G1-G2-G3 generating debug information to an executable file

-W Close all warnings

-W all,error-wall Show all warnings-werror put all warnings in error

-C Compile Build target file not linked

-E Pre-compilation

-S compiled into a compilation

-D Add a macro definition to the command line

-X The compilation type of the specified language gcc-x C xxxx.c gcc-x assembler Xxx.s

-STD=C89-STD=C99 compilation criteria for specified languages

Note: The GCC compiler automatically calls the linker ld

Restrict keyword int add (int* restrict a) {} optimize compiler compilation, pointer-to-value in function parameters in register, increase efficiency, support in C99, c89 not support

And then it's fun to compile the static library

Usually we need to call many library compilations, simple examples

Write a add.c save int add (int a,int b) {return a+b;}

Write a SUB.C subtraction function

Write a main.c call add,sub

Compiling gcc main.c add.c sub.c ====> a.out

When we write a lot of files, it seems very inconvenient, there is a static library generation

First step: Compile into the target file

Gcc-c-static ADD.C = = = "Target file add.o

Gcc-c-static sub.c=====> target file sub.o

Step two: Archive into a static library

Ar Tool came up

-R ar-r ku.a add.o SUB.O = = = Archive the target file as a static library ku.a

-T ar-t ku.a shows which target files your static library contains

NM tool (view function symbol functions)

NM target file/executable/static library/dynamic Library


Small application: * * * * use gcc static library, enter a diamond radius, print diamond

1. Write a RADIUS input library package Ioinput Library

2. Write a diamond-shaped print library to encapsulate the graphics library

Program: 1. Implement input 2. Implement Diamond 3. Compile into a static library 4. Call the static library

It's a fun ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.

Linux Environment Programming compiler tool and dynamic State Library

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.