简体   繁体   中英

Why is Visual Studio 2012 running custom build step when source file hasn't been changed?

I'm using yacc and lex with Visual Studio 2012 C++/CLI and have created a custom build step for the yacc source file as shown in image below

自定义构建属性页面

There are two dependencies for the output file. They are the yacc source file icl5kyacc.y and the yyparse.c template file. Every time I build the solution the custom build step runs even when the yyparse.c and icl5kyacc.y source files have not been modified. Here's directory listing following a build.

  21-Sep-2012  10:19:18p         28,210    A icl5kyacc.y
  17-Sep-2012   7:32:06p          9,042    A yyparse.c
  22-Sep-2012  11:43:56a         38,233    A ICL5KYACC.cpp
  22-Sep-2012  11:43:56a          2,160    A icl5kyacc.h

And after building again

2> Generating icl5kyacc.cpp from icl5kyacc.y

  21-Sep-2012  10:19:18p         28,210    A icl5kyacc.y
  17-Sep-2012   7:32:06p          9,042    A yyparse.c
  22-Sep-2012  11:45:46a         38,233    A ICL5KYACC.cpp
  22-Sep-2012  11:45:46a          2,160    A icl5kyacc.h

Am I mistaken in believing that the using a custom build step should automatically apply standard dependency rules between the input and output files of the build step? One thing I'm curious about is the %(AdditionalInputs) macro which Studio put in for me under Additional Dependencies. Not sure what that is or if that is somehow pointing to a file that is being modified.

Are you sure that your Output files are actually located where you specify?

Looking at your listing you have the input listed at %(Directory)yyparse.c (this should also include the .y file as well). Shouldn't your output also be located in %(Directory)icl5kyacc.h and %(Directory)ICL5KYACC.cpp , seeing that your listing seems to indicate that they go in the same directory.

The build task will rerun if it cannot find the output files or if the output files are older than the input files. If your path is wrong to the output files then the tool will not find them and assume that the build task needs to run again.

The problem was that %(Directory) was a relative path from the parent of the solution to the project directory "ICL5K\\ICL5K\\" and during the build the current directory is already the project directory. So the yyparse.c dependent was being looked for in C:\\ICL5K\\ICL5K\\ICL5K\\ICL5K. I should have used $(ProjectDir) which is a full path from the root including the drive specifier "C:\\ICL5K\\ICL5K\\". But even better was to realize that all the input and output files were in the project directory and that was already the current default directory and to remove all directory macros as shown below 图像在这里 Also it is not necessary to specify icl5kyacc.y as a dependent since the custom build step is a property of icl5kyacc.y so that file it is already included as a dependent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM