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