[Linux] C ++ programming (Vim)

Source: Internet
Author: User

1. Compile (compile)

Meaning: Use the compiler (compile)Source codeGenerate a binary target file. It is. OBJ in window. It is a. o file in Linux.

Requirements: required by the compiler. The syntax is correct. The compiler detects onlyProgramWhether the syntax, function, and variable are declared, and the function cannot be defined.

Compilation Syntax: G ++-C file. cpp where-C is compile to generate the target file of file. o

2. Link)

Meaning: All files that need to be connected to the function, and you can link them together to form executable files.

Syntax: G ++ file. O-o file.exe where-O indicates generating an executable file (output ). The default value is a. Out.

[Merge] G ++ file. cpp-O file.exe

3. Library)

Meaning: for a large project with many source files, in order to avoid repeated compilation and facilitate the compiler link, some commonly used target files are usually packaged (archive ), so it became a library ). In Windows, this package is called "library file", that is, the. Lib file. In UNIX, It is the archive file, that is, the. A file.

Syntax: 1) ar -- create, modify, and extract from archives.
@ Usage: Ar Cr lib *****. A file1.o file2.o // ***** indicates the custom library file name.
Label C (create): creates a database if the library does not exist;
Tag R (replace): if an object file to be added already exists in the database, the old object file will be replaced.

In fact, Ar is just a packaging tool and is the first character of archive. It connects the first part of a series of target files and embeds an index table so that the compiler can conveniently find the required functions. In general, because of the existence of function index tables, the link to the database is faster than the link to common object files. If Ar fails to complete this index, you can also manually use the following ranlib command to create an index table.

2) ranlib -- generate index to archive.
@ Usage: ranlib lib *****.

3) nm -- list symbols from object files.

Nm can be used to display the index table built by ranlib. You will see the function names in all libraries (except the template function ).

4. link the library during compilation

You have created your own library. To use related functions in the future, you only needCodeDeclare the function to be used (must be the same as the function defined in the library ). The name and location of the warehouse to be delivered during the link:

G ++ file1.o file2.o-O program.exe-l ****

-L followed by the Directory address where the library file is located, and-l followed by the Library name.

When linking, the compiler searches for the library file named lib ***. A under the specified directory address.



 


Related Article

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.