Generating static and dynamic libraries under Linux [Linux]

Source: Internet
Author: User

g++ using g++ to compile Hello World

1. Writing the Hello World code

2. Build the executable file using the g++ command hello.out

3. g++ Command Rules

Precompiled g++-E hello. cpp -o hello.i compile    g+ +-s hello.  CPP -o hello.s Assembly    G+ C hello.  CPP -o hello.o
Command explanation

1. Precompiled g++-E hello.cpp-o hello.i

Expand # include <iostream> to capture the display of the last screen

2. Compile g++-S hello.cpp-o Hello.s capture the display of the last screen

3. Compilation, generating object file g++-C hello.cpp-o hello.c display binary file

4. Link, write three files add.h add.cpp main.cpp

Compile run g++ add.h add.cpp main.cpp-o main.out

Static library and dynamic library generation

Static library: Linux: *.a windows: *.lib

Dynamic library: Linux: *.so windows: *.dll

Creation and use of static libraries

Static libraries are aggregates of some target files

Create a static library file using AR

1. Compile the Add.cpp file to generate the ADD.O file g++-C add.cpp

2. Create a. A file from the. o file using ar ar-r libadd.a add.o

3. Use the. a file g++ main.cpp-l.-ladd-o Main

Dynamic library creation and use

1. Create a. So file g++-shared-fpic add.cpp-o libmyadd.so

2. Use the. So file link main g++ main.cpp-l.-lmyadd-o main.out

3. Add the path and run Main.out ld_library_path=. ./main.out

Generating static and dynamic libraries under Linux [Linux]

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.