Precautions for Linux program Compilation

Source: Internet
Author: User

I have been working on some open-source projects in Linux in the last week. In fact, I have been playing a hard job a long time ago. This time I encountered some problems when compiling the program again, so I will record it here.

 

1. When the C ++ program needs to include the header file of a program written in C language, the C ++ file should include:

Extern "C"

{

# Include "Your header file"

}

Note: C is written in uppercase.

For example, a directory contains main. CPP hello. c hello. h. hello. c function, then in main. in CPP, you must include hello. h header file to call Hello. therefore. write in CPP as follows:

Extern "C"

{

# Include "Hello. H"

}

Otherwise, the system will prompt that the corresponding function cannot be found during the compilation link, for example:

:(.text+0x7): undefined reference to ...

 

2. When compiling some programs, you may encounter problems such as the corresponding library not found. In this case, you can compile and install the source code of the corresponding library by yourself.

You can download the source code to compile and install the library. In most cases, it is installed in the/usr/local directory by default, however, when compiling the program, the system will prompt that the corresponding library cannot be found. At this time, you need to find the corresponding library in/etc/lD. so. add/usr/local/lib in the conf file, and run the following command:

Ldconfig-V

.

Therefore, ldconfig-V is recommended every time you add a library file to/usr/local/lib.

 

3. view the library on which the executable file depends

1. on PC Linux:

For example: # LDD/mypath/Hello

2. on ARM Linux:

For example: # arm-Linux-readelf-d hello

 

 

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.