Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the Visual Studio C compiler have an equivalent to GCC's -M?

I would like to automatically generate a Makefile dependency list, but I am using Visual Studio 2005. If I were using GCC, I could pass -M (or one of the many variants) to create this dependency list.

Looking through the command line options to cl.exe, I don't see anything obvious. I can handle tweaking the output with post-processing, but the closer the better.

like image 700
Shepmaster Avatar asked Nov 23 '09 17:11

Shepmaster


People also ask

Does Visual Studio include C compiler?

The Visual Studio build tools include a C compiler that you can use to create everything from basic console programs to full Windows Desktop applications, mobile apps, and more.

Which compiler is best for C programming in VS Code?

GCC via Mingw-w64 on Windows. Microsoft C++ compiler on windows. Clang for XCode on MacOS.

Does Visual Studio support C17?

Support for C11 and C17 standards is available in Visual Studio 2019 version 16.8 and later. Support requires an updated Universal C Runtime (UCRT) and Windows SDK version to work properly with the conforming preprocessor ( /Zc:preprocessor ).

Does Visual Studio have its own compiler?

Microsoft C++ Compiler (MSVC) This is the default compiler for most Visual Studio C++ projects and is recommended if you are targeting Windows.


3 Answers

In the cl.exe of Visual Studio 2005 at least, there is the option /showIncludes.

like image 102
js. Avatar answered Nov 05 '22 22:11

js.


I had to deal with that exact problem. We wanted to add a script that replaces the -M option. Here's how I did it:

  1. find a source preprocessor ( and the include paths & defines you need )
  2. run it on the file you need, and it should produce a preprocessed version.
  3. most preprocessors have a switch that enables extra info ( such as the file where some code snippet came from )
  4. write a simple script to extract all the header names
  5. create a set out of them, so that you filter out duplicates.

It's how I've done it, and it worked. Good luck!

like image 20
Geo Avatar answered Nov 05 '22 22:11

Geo


The compiler stores dependencies in the intermediate .idb file. You might be able to parse it from there.

See https://msdn.microsoft.com/en-us/library/kfz8ad09.aspx

You can find all included files prefixed with "/mr/inversedeps/" or "/ipm/header/" in there, it seems.


I think you should also find dependencies in other intermediate files, e.g. "CL.read.1.tlog".

like image 2
masterxilo Avatar answered Nov 05 '22 22:11

masterxilo