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]