Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to quickly locate the header file path by using the gcc compilation option to solve the problems in compilation

Shulou Source: shulou.com Published: 2022-06-02 00:46:40 09月15日 Update

This article shows you how to use the gcc compilation option to quickly locate the header file path to solve the compilation problem, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.

C / C++ when the project is too large, there will often be some header files with multiple copies.

As shown in the following figure:

It is possible to have multiple inconsistent codes in the same header file.

If you happen to reference such a header file, it may result in a compilation error.

For example:

Xx.h in directory A has a variable h

Xx.h in directory B has no variable h

What we may refer to in our compilation path is the xx.h under the B directory, which may lead to access to the non-existent variable h and cause compilation problems.

So how do we quickly locate the path to the header file we referenced?

Gcc has related compilation options-MMD or-MD

`- MD'

`- MD' is equivalent to`-M-MF FILE', except that `- E' is not

Implied. The driver determines FILE based on whether an `- o'

Option is given. If it is, the driver uses its argument but with

A suffix of `.d', otherwise it take the basename of the input file

And applies a `.d 'suffix.

If `- MD' is used in conjunction with`-eBay, any `- o' switch is

Understood to specify the dependency output file (but * note-MF:

DashMF.), but if used without `- eBay, each`-o' is understood to

Specify a target object file.

Since `- E' is not implied,`-MD' can be used to generate a

Dependency output file as a side-effect of the compilation process.

`- MMD'

Like `- MD' except mention only user header files, not system

Header files.

It is generally added to the FLAGS of gcc in our Makefile file and can be modified according to different variables.

When you execute make to compile, you will get a file with xx.cpp = > xx.d

Open it with the editor to see the complete header file path:

The path of the header file used can be clearly seen from the figure

It's application/share/webapp_frame/include/webapp_headinfo.h.

Not server/share/webapp_frame/include/webapp_headinfo.h files.

This makes it easy to quickly locate and fix some compilation problems.

The above is how to use the gcc compilation option to quickly locate the header file path to solve the compilation problems, have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Files compilations paths problems positioning variables directories contents skills knowledge aspects different same concise consistent concise code that is regular meetings huge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Redmi Shulou Tech Info MySQL vpn