g++ search mechanism and mingw environment configuration under Window

When writing this short article, I mainly remind myself that when #include "" and #include <>, it is often said that the search starts from the current path and the search starts from the system path. What exactly does the system path refer to here.

When writing C/C++ programs under windows, sometimes you don't want to use a big block like VStudio, and use the writing mode of mingw+sublime instead. Simple Installation - Simple to use.

1. First configure the g++ startup path. To directly copy the mingw folder to the E drive as the working directory of the compiler, you need to append E:\mingw32\Bin to My Computer/Computer->Properties->Advanced System Settings->Environment Variables->System Variable Path. Type g++ -v or g++ --version in the CMD window to query the g++ version information used. The information I installed is as follows:

Enter image description

2. If we write a simple program of helloworld.cpp that includes <iostream> and <cstdlib> system header files, we will find the following error description that the system header file cannot be found when compiling directly:

Enter image description

The following is why we need a brief explanation. When using g++ to compile a program, the search from the system directory refers to the search from the file path indicated by the system environment variable CPLUS_INCLUDE_PATH. So we create a new CPLUS_INCLUDE_PATH in the system variable and specify the value as E:\mingw32\Include;E:\mingw32\Include\G++, we recompile, and we will find that the Hello.exe program has been generated, run and print Hello, world !.

3. Configure the default library search directory of g++ again, create a new LIBRARY_PATH in the system variable, and specify the value E:\mingw32\Lib

4. If you use gcc to compile a pure C program, we also configure it, create a new C_INCLUDEDE_PATH in the system variable, and specify the value E:\mingw32\Include.

5. At this point, the configuration of mingw under the window has been clear, and it is also clear which directory is the search from the system directory that is often said in C/C++.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325397960&siteId=291194637