Linux gcc compile-time header files and library file search paths

Source: Internet
Author: User

First, the header file gcc at compile time to find the required header file: ※ Search will start from-I ※ then find the environment variable c_include_path,cplus_include_path,objc_include_path※ and then find the default directory/usr/incl Ude/usr/local/include/usr/lib/gcc-lib/i386-linux/2.95.2/include/usr/lib/gcc-lib/i386-linux/2.95.2/. /.. /.. /.. /include/g++-3/usr/lib/gcc-lib/i386-linux/2.95.2/. /.. /.. /.. /i386-linux/include Library file But if there is a given prefix when the GCC is installed, then/usr/include prefix/include prefix/xxx-xxx-xxx-gnulibc/ Include Prefix/lib/gcc-lib/xxxx-xxx-xxx-gnulibc/2.8.1/include second, the library file compile time: ※GCC will go to find-l※ and then find the environment variable of GCC library_path※ then find the default directory /lib:/usr/lib:/usr/local/lib: It was written in the program when compile GCC.

Third, run-time dynamic Library search Path

1. Specify the dynamic library search path in the configuration file/etc/ld.so.conf

2. Specify the dynamic library search path through the environment variable Ld_library_path (when multiple dynamic library search paths are specified through the environment variable, the paths are separated by a colon ":") 3,  Specify the dynamic library search path for the program when compiling the target code (you can also specify the program's dynamic Library search path when compiling the target code). This is specified through the GCC parameter "-wl,-rpath,".  When more than one dynamic library search path is specified, the path is separated by a colon ":" 4, the default dynamic library search path/lib/usr/lib can be obtained by executing the executable POS to find out which dynamic library it found, to obtain the 1th Dynamic Library search order, and then delete the dynamic library, Then execute the program POS, get the 2nd Dynamic Library search path, and then delete the 2nd search dynamic library, so back and forth, you will get the order of the Linux search dynamic library. The corresponding relationship between the output of the program POS execution and the dynamic library found in Table 1 shows the dynamic Library search path that is used by the program POS output results in the specified way././libpos.so The Dynamic library search path specified when compiling the target code/root/test/env/lib/ro ot/test/env/lib/libpos.so environment variable Ld_library_path the specified dynamic library search path/root/test/conf/lib/root/test/conf/lib/libpos.so configuration file etc  The dynamic library search path specified in/ld.so.conf/lib/lib/libpos.so the default dynamic library search path/lib/usr/lib/usr/lib/libpos.so the default dynamic library search path/usr/lib The order of search path search for dynamic libraries is: 1. The dynamic library search path specified when compiling the target code; 2. The environment variable ld_library_path the specified dynamic library search path; 3. The dynamic library search path specified in configuration file/etc/ld.so.conf;
4. The default dynamic library search path/lib/usr/lib.

Linux gcc compile-time header files and library file search paths

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.