Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report