1. About the GCC search a header file and the static library catalog, although can add parameters change at compile time, but can a permanent change? Let later don't have to use the parameter specifies the directory that,
2. The GCC is what find header files according to the corresponding static library files? Why even in the same directory, some can automatically link library GCC, we specify others need?
CodePudding user response:
The header file search
The header file search order:
1. By the parameter - I specified path (specified path with multiple paths, according to the order of the specified path search)
2. Then find the GCC environment variable C_INCLUDE_PATH, CPLUS_INCLUDE_PATH, OBJC_INCLUDE_PATH
3. Get the default directory
The/usr/include
/usr/local/include
The/usr/lib/GCC - lib/i386 Linux/2.95.2/include
The/usr/lib/GCC - lib/i386 Linux/2.95.2/../../../../include/g + + - 3
The/usr/lib/GCC - lib/i386 Linux/2.95.2/../../../../i386 Linux/include
If you don't specify one, that is to find it from 2, 2 also didn't specify, if just to find it from 3, including the/usr/include is relative to the GCC, because generally GCC installed in/usr/bin/GCC, so the/usr/include is the default search path
Link library search path
1. The compilation of the target code specified dynamic library search path;
2. The environment variable LIBRARY_PATH (compile time), LD_LIBRARY_PATH (runtime) specified dynamic library search path;
3. Configuration file/etc/ld. So, the conf specified in the dynamic library search path;
4. The default dynamic library search path/lib.
5. The default dynamic library search path/usr/lib,
CodePudding user response:
refer to the building of six Payne reply: 1. About the GCC search a header file and the static library catalog, although can add parameters change at compile time, but can a permanent change? Let later don't have to use the parameter specifies the directory that, 2. The GCC is what find header files according to the corresponding static library files? Why even in the same directory, some can automatically link library GCC, we specify others need? Use a makefile CodePudding user response:
reference 1st floor qybao response: header file searchThe header file search order: 1. By the parameter - I specified path (specified path with multiple paths, according to the order of the specified path search) 2. Then find the GCC environment variable C_INCLUDE_PATH, CPLUS_INCLUDE_PATH, OBJC_INCLUDE_PATH 3. Get the default directory The/usr/include /usr/local/include The/usr/lib/GCC - lib/i386 Linux/2.95.2/include The/usr/lib/GCC - lib/i386 Linux/2.95.2/../../../../include/g + + - 3 The/usr/lib/GCC - lib/i386 Linux/2.95.2/../../../../i386 Linux/include If you don't specify one, that is to find it from 2, 2 also didn't specify, if just to find it from 3, including the/usr/include is relative to the GCC, because generally GCC installed in/usr/bin/GCC, so the/usr/include is the default search path Link library search path 1. The compilation of the target code specified dynamic library search path; 2. The environment variable LIBRARY_PATH (compile time), LD_LIBRARY_PATH (runtime) specified dynamic library search path; 3. Configuration file/etc/ld. So, the conf specified in the dynamic library search path; 4. The default dynamic library search path/lib. 5. The default dynamic library search path/usr/lib, The key is the path where is write? Always can't be written in the book of the inside of the GCC? And my environment is mingw, not Linux, When I compile is to specify the GCC command-line compiler, don't use the makefile, so, for those who can automatically find the object library, such as the standard library, win32 library, how does it know which is which? CodePudding user response:
The reference 3 floor six Payne reply: where the key is the path is to write? Always can't be written in the book of the inside of the GCC? And my environment is mingw, not Linux, When I compile is to specify the GCC command-line compiler, don't use the makefile, so, for those who can automatically find the object library, such as the standard library, win32 library, how does it know which is which? You didn't look carefully? Not to tell you that the order of the search path, you don't have a makefile, use environment variables ok! Inlcude environment variable C_INCLUDE_PATH CPLUS_INCLUDE_PATH, OBJC_INCLUDE_PATH The link environment variable LIBRARY_PATH (compile time), LD_LIBRARY_PATH (runtime) Environment variables not? Don't own Google baidu search how environmental variables https://blog.csdn.net/Flood_Dragon/article/details/12363705 CodePudding user response:
reference 4 floor qybao response: don't you look carefully? Not to tell you that the order of the search path, you don't have a makefile, use environment variables ok! Inlcude environment variable C_INCLUDE_PATH CPLUS_INCLUDE_PATH, OBJC_INCLUDE_PATH The link environment variable LIBRARY_PATH (compile time), LD_LIBRARY_PATH (runtime) Environment variables not? Don't own Google baidu search how environmental variables https://blog.csdn.net/Flood_Dragon/article/details/12363705 Yes,,,,,, I'm not asking what the search path, to see whether the search path for GCC I add a parameter output to not to go? You said these environment variables, including your this link, the key is, there is no these environment variables, it is the same work, still can find the location of the library, this is what I confused, I want to know is, the record of the path string in where? Since environment variable is not, then where is it? I searched the whole text content in the mingw, without these paths, so I wonder if it is written in the GCC or ld program? The second, which is the most important question, GCC is according to find the corresponding library, for example, I include math.h h, or call mathematical functions, GCC how do you know what is needed libraries? Why do some libraries, folders are obviously, it is can't find, need we use parameters to link? CodePudding user response:
reference 5 floor six Payne reply: Quote: refer to 4th floor qybao response: You didn't look carefully? Not to tell you that the order of the search path, you don't have a makefile, use environment variables ok! Inlcude environment variable C_INCLUDE_PATH CPLUS_INCLUDE_PATH, OBJC_INCLUDE_PATH The link environment variable LIBRARY_PATH (compile time), LD_LIBRARY_PATH (runtime) Environment variables not? Don't own Google baidu search how environmental variables https://blog.csdn.net/Flood_Dragon/article/details/12363705 Yes,,,,,, I'm not asking what the search path, to see whether the search path for GCC I add a parameter output to not to go? You said these environment variables, including your this link, the key is, there is no these environment variables, it is the same work, still can find the location of the library, this is what I confused, I want to know is, the record of the path string in where? Since environment variable is not, then where is it? I searched the whole text content in the mingw, without these paths, so I wonder if it is written in the GCC or ld program? The second, which is the most important question, GCC is according to find the corresponding library, for example, I include math.h h, or call mathematical functions, GCC how do you know what is needed libraries? Why do some libraries, folders are obviously, it is can't find, need we use parameters to link? you didn't watch carefully, not a makefile, rather than in the environment variables, that is the third case, it says in the relative path of the installation path of GCC CodePudding user response:
refer to 6th floor qybao response: Oh, come on brother, you never know what I'm talking about, I still look for books CodePudding user response:
Not don't understand what you ask, but don't you understand my answer the content of the GCC will automatically search the include and lib path, that is inside the GCC, 123 more than it will tell the order of the search path, 1 and 2: no, why would search 3? How to search 3, isn't it simple? GCC to take to their installation path, such as installed in C: \ \ MinGW \ bin, GCC after finding the path with a relative path way to find an include, the C: \ \ MinGW \ include, from C: \ \ MinGW \ bin to C: \ \ MinGW \ include how to use relative paths will find? C: \ \ MinGW \ bin \.. Can find the C: \ \ MinGW (parent folder), then the parent folder \ include, namely C: \ \ MinGW \ bin \.. \ include in order to find the include path, how to find the GCC installation path? A program that it's difficult to find their own path? The main function has a argv [0] parameters, bat it can get, through % ~ dp0 parameter nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull