Issue with header file dependency file (.d) generation

Hi Compiler Team,

I frequently use the nvc/nvc++ compiler for OpenACC. Recently I started generating dependency files to make the build process incremental.

In gcc/g++ I use the ‘-MMD -MP’ flags while compiling object files. gcc by default generates the .d files in the same directory as the .o files when compiled. I realise that it is different with nvc/nvc++:

  1. -MP does not work with it.
  2. .d files are generated in the directory where the command (nvc/nvc++) is run from.

I want the dependency files to be generated in the same directory as the object files as it reduces clutter. To achieve this I tried using the C preprocessor (cpp) to generate the .d files and then compiling using nvc/nvc++ in the same make rule. But nvc/nvc++ does not detect changes in header files if done that way.

Is there any way to achieve my requirement in the NVIDIA HPC SDK (21.9) I am using? Why does nvc/nvc++ not generate the .d files in the same directory as the object files? Any plan to add this in future?

Hi beckergrey,

I double checked, but didn’t find a way to match this behavior, nor do we support the “-MP” option. Hence I added RFEs for both, TPR #32156 for -MMD, and TPR #32157 for -MP.

Not sure we’ll be able to do this, but I’ll let engineering see what can be done.

-Mat

Dear Mat,

When you mean ‘didn’t find a way to match this behavior’, I hope you meant you couldn’t reproduce the gcc/g++ output to the nvc/nvc++ output.

Also, please update once engineering has a solution.

Thanks,
Beck

Hi Beck,

Meaning that we don’t have a method to change the directory where the dependency file gets outputed.

I’ll post a notification if/when either of these requests are available in a release.

-Mat

Dear Mat,

Thanks, do let me know once it is available.

I kept on the issue and have temporary fix. For anyone else requiring the same behaviour, put this command before the nvc/nvc++ command in the make rule for building objects:

g++ -E -MMD -MP -MF $(OBJDIR)$(*F).d -MT $(OBJDIR)$(*F).o $(INCDIRS) $< >/dev/null 2>&1

Everything else is the same. Not the most elegant solution, but it works!

Few caveats.

  1. Cannot use ‘cpp’ (C preprocessor) as it has similar behaviour to nvc/nvc++.
  2. ‘>/dev/null 2>&1’ is to suppress the output from the preprocessor. There might be a better way for this.

@MatColgrove, please add suggestions/corrections as required.

Hi Beck,

We’ve updated the -MMD behavior to match GCC’s, i.e. the dependency file will be placed in the same directory as the object file. Though they haven’t yet added support for -MP.

% nvc -V23.3 -MMD dir/test.c -c -o dir/test.o
% ls test.d
test.d
% rm test.d
% nvc -V23.5 -MMD dir/test.c -c -o dir/test.o
% ls test.d
ls: cannot access 'test.d': No such file or directory
% ls dir/test.d
dir/test.d

-Mat

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.