Is there dependency generation flag for MSVC like gcc's -M

独自空忆成欢 提交于 2019-12-10 02:36:59

问题


Is there dependency generation flag for MSVC like gcc's -M flag.

Every C++ compiler I have ever used had this kind of flag. How can I create dependencies automatically with MSVC cl compiler.

  1. I'm interested for only latest compiler versions i.e. MSVC9 or later but if it works with MSVC8 it is fine as well.
  2. If there is built-in external tool to do this (I mean, not cl), it would be fine as well

回答1:


This batch script may be what you and I have been looking for, though I have not tested it.

Pass file as %1 and include path as %2

@ECHO %1: \
@FOR /F "tokens=1,2,3,*" %%A IN ('cl /nologo /c %1 /Zs /showIncludes /I%2') DO @IF NOT "%%D"=="" echo %%D \

Outputs:

filename.c: \
header.h \
someotherheader.h



回答2:


You may be able to use:

/showIncludes show include file names

although you will probably also need some additional filtering afterwards to get the format that you need.



来源:https://stackoverflow.com/questions/2987298/is-there-dependency-generation-flag-for-msvc-like-gccs-m

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!