Basic use of C ++ compiler g ++ in Linux

Source: Internet
Author: User
Document directory
  • Basic use of C ++ compiler g ++ in Linux
Basic usage of C ++ compiler g ++ in Linux {
Commit it (this)
} "Onmousedown =" function onmousedown ()
{
CA. Q ('blog _ entryview_assist_topright ');
} "Href =" javascript: void (0); "> label: Linux C ++ compiler g ++ basic usage classification: Linux system 16: 08g ++ is the c ++ compiler in Linux. It takes four steps to compile the code.

1. pre-process and generate the. I file
2. Convert the pre-processed files into assembly languages to generate file. S.
3. a. o file is generated by means of compilation into the target code (machine code ).
4. Connect the target code to generate an executable program

Frequently Used parameters for compiling C ++:

-C

Compile only, not connect. Example: G ++-C helloworld. cpp
Only generate helloworld. o not connected

-O

Specify the output file name. Example: G ++-C helloworld. cpp-o abc. o
Helloworld. O is generated by default. After-o abc. O is used, ABC. O is generated.

-I

Append the path of a letter header file. Example: G ++ helloworld. cpp-I "/usr/helloworld/include"

-L

A small L is attached with a library. For example, to use libabc. So, G ++ helloworld. cpp-labc

-L

Add a library path, such as G ++ hello. cpp-L "/usr/Hello/lib"-labc

-Shared

Generate a dynamic library file, for example, G ++-shared hellp. cpp-O libhello. So

When calling a dynamic library, several problems may occur frequently. Sometimes, the directory where the library's header files are already included through include, and the file where the library is located is guided by the "-l" parameter, the "-l" library name is specified. However, when you run the LDD command to check whether the so file with the specified link is missing. In fact, the shared library on the Compilation link does not mean it can be found during execution. Therefore, "-l" is useless for execution. You need to specify the path of the shared library. There are three methods:
A. Modify LD_LIBRARY_PATH to specify the path of the shared library. LD_LIBRARY_PATH: The environment variable indicates the path where the dynamic connector can load the dynamic library. Run the following command on the terminal:
[Root @ localhost sharelib] # export LD_LIBRARY_PATH =.
[Root @ localhost sharelib] # export LD_LIBRARY_PATH = Your lib dir Export
B. Specify the directory of the dynamic library through the/etc/lD. So. conf file. Run the ldconfig command to update the path of the shared library. This method can solve the problem that the library cannot be linked once and for all.
C. Copy the library file to/lib, and then ldconfig will be OK. This method is clever and destroys the purity of the original library files. It should not be the preferred method.
Modify the/etc/lD. So. conf file and call/sbin/ldconfig to have the root permission. If you do not have the root permission, you can only output LD_LIBRARY_PATH.

In Linux, the file type does not depend on its suffix, but generally speaking:
. O is the target file, which is equivalent to the. OBJ file in windows.
. So is a shared library and is a shared object, used for dynamic connection, similar to DLL
. A is a static database and multiple. O files are combined for static connections.
. LA is a shared library automatically generated by libtool. It mainly records some configuration information.

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.