2.0 database function construction

Source: Internet
Author: User

Labels: Framework library Assembly gcc C Language

The method for reading the character length when the bytes in the struct program are aligned. The program is as follows:


There are three types in the program: Char, Int, and short: The program reads data in four-byte alignment mode (read every four bytes ), in the program, the computer will first read the char type, the length of the read is 2 bytes, because the int occupies 4 bytes, therefore, when reading an int, the computer will automatically select a multiple of 4 for reading. That is, the computer will empty two bytes after reading the two bytes of char, and then read the four bytes of the int, at this time, the Computer Reads 8 bytes, and then the computer will read the 2 bytes of short, and then read the 1 byte of char, because the computer reads the length according to the four-byte alignment, it will automatically leave one length after the char, so the length read by the computer is 12. That is, the program running result is: length = 12.

 

Static library Compilation:

Ar-Rs libmy_math.a *. o

This command is used to package all. O files into libmy_math.a (static library), and my_math is the name of the static library.

Ar-T libmy_math.a

This command is used to package the. o file into a static library.

GCC file. C (file for writing the main function)-L.-lmy_math-o file

This instruction indicates compiling the file. c file into an executable file. L. indicates the path followed by the path, that is, the location of the warehouse.

 

Dynamic library Compilation:

Gcc-FPIC *. c

This command is used to compile all. c files into. O files.

Gcc-shared-O lib_math.so *. o

The meaning of this instruction is: Compile the. o file into a dynamic library lib_math.so (dynamic library ).

LDD file indicates viewing links.

Export LD_LIBRARY_PATH = $ ld_libary_path :.

The meaning of this command indicates that the dynamic library in the current path is found during the running and loading.

Echo $ ld_libaray

This command indicates whether the program has configured a path. If yes, the command (:.) is displayed (:.).

 

Dynamic library update:

1. First move the. h file to/usr/include

2. Move the original dynamic library to/usr/lib

3. Change the file in the definition

4. Compile gcc-FPIC-C *. c into a. o file.

5. After gcc-shared-O libmy_math.so *. O is used, my_math.so (dynamic library) is generated ).

6. Move the dynamic library to/usr/lib and overwrite the original dynamic library.

7. Use GCC file. C-lmy_math-o file for compilation.

7. Use./file to view the executable file.

Note: The update of the dynamic library only changes what is in the definition, so the framework of the dynamic library does not change.

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.