Linux header files and library file settings

Source: Internet
Author: User
Tags gtk

Gcc/g++ will look for the system's default include and link paths, along with the path you specify in the compile command. The path you specify is not said, here is a description of the system automatic search path.

"1" Include header file path in addition to the default/usr/include,/usr/local/include and other include paths, you can also add the path to the system include by setting environment variables:

# C Export c_include_path=xxxx: $C _include_path # CPP export cplus_include_path=xxx: $CPLUS _include_path The above changes can be directly command line input (one-time), can be completed in/etc/profile (for all users), or in the user's home directory in the. bashrc or. Bash_profile (for a user), after the modification, the login will take effect. The "2" link library file path link library file is used when connecting (static libraries and shared libraries) and running (only for programs using shared libraries), and its search path is set on the system (or can be specified by-l-l in the Compile command, which is referred to by using the system default search path). The general Linux system uses/lib/usr/lib/usr/local/lib as the default library search path, so the link library files in these directories can be searched directly (no need to specifically specify the link library path). For a library other than the default search path, you need to add its path to the gcc/g++ search path. The search path for a linked library file is specified in two ways: 1) modify/etc/so.ld.conf 2) modify the environment variable to add your own path 1) add a dynamic-link library search path to an environment variable: Export LD_LIBRARY_PATH=XXX: $LD _ Library_path static link library search path: Export library_path=xxx: $LIBRARY _path above changes can be directly command line input (one-time), can be completed in/etc/profile (for all users), can also be added in the. bashrc or. Bash_profile in the user's home directory (for a user), and re-login will take effect when the modification is complete. 2) Add the specified link library search path (root permission required) in/etc/ld.so.conf, and then run/sbin/ldconfig to achieve the effect of refreshing/etc/ld.so.cache. Both of these methods can achieve the effect of specifying a link library search path. The second way to set up the search path is sufficient for the location of the library (including shared libraries and static libraries) when the program is connected, but it is not enough for programs that use shared libraries. This is because in order to speed up the location of shared libraries during program execution, and to avoid the inefficient use of search paths to find shared libraries, the system reads/etc/ld.so.cache and searches from them directly. /etc/ld.so.The cache is a non-text data file that cannot be edited directly, and it is generated by the/sbin/ldconfig command to centralize shared library files under these search paths (ldconfig command to root) based on the search path set in/etc/ld.so.conf. Permission execution). Therefore, in order to ensure the location of the library when the program executes, after setting the library search path in/etc/ld.so.conf, run the/sbin/ldconfig command to update the/etc/ld.so.cache file. The Ldconfig function is to cache the library file under the path specified by/etc/ld.so.conf to/etc/ld.so.cache. So when you have installed some library files (for example, just installed glib), or modified ld.so.conf to add a new library path, you need to run/sbin/ldconfig so that all library files are cached to Ld.so.cache, otherwise the modified content is not effective. When a program is connected, the search Paths for library files (static libraries and shared libraries) can be explicitly specified with the-L and-l parameters, in addition to the settings above. Because the path set with-L is prioritized, the path to the library to which you want to connect is typically specified in this way when you connect. Note: 1) When configuring the environment variable, do not add a space before the equal sign, or you may have command not found 2) after modifying/etc/ld.so.conf, when the system restarts, all GTK2-based programs will use the newly installed GTK + library at run time. Due to the changes in the GTK + version, some applications are sometimes subject to compatibility problems, causing some programs to run abnormally. To avoid these situations, the setting of the search path for the library during GTK + and its dependent libraries is set in an environment variable way export ld_library_path=/opt/gtk/lib: $LD _library_path

Settings for Linux header files and library files

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.