skip to Main Content

Under gcc 11.3.0, when entering the command, gcc -M -MD sourcefile.c, a file named "a-sourcefile.d" is created. However, under gcc 9.4.0, the "a-" prefix is not present.

Is this correct behavour?

I was expecting .d files without the "a-" prefix.

EDIT: I noticed the issue when using a makefile but I am able to reproduce the issue without a makefile, using commands entered manually.

More detailed information:

I have 2 different machines:
Machine 1:

$ gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0

Machine 2:

$ gcc --version
gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0

Assume each machine has identical directories containing 3 files: main.c, library.c and library.h.

Contents of main.c:

#include <stdio.h>
#include "library.h"

int main(void)
{
  printf("Hello worldn");
  LibFunc1();
  return 0;
}

library.c:

#include <stdio.h>
#include "library.h"

void LibFunc1(void)
{
  puts("Library Function 1");
}

library.h:

void LibFunc1(void);

commands run on both machines:

gcc -M -MD library.c
gcc -M -MD main.c

Contents of directory on Machine 1:

$ ls
library.c  library.d  library.h  main.c  main.d

Contents of directory on Machine 2:

$ ls
a-library.d  a-main.d  library.c  library.h  main.c

So, why the discrepancy? No makefile, no special variables being used (as far as I am aware unless there’s some environment variable that is persistent).

Machine 2 is a fresh install and was booted up just before the commands were entered.

2

Answers


  1. Chosen as BEST ANSWER

    It turns out that there actually is a bug about this issue in the gcc bug tracker: Bug 109183 - [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files

    Thanks @John Bollinger for responding.


  2. Under gcc 11.3.0, when entering the command, gcc -M -MD sourcefile.c, a file named "a-sourcefile.d" is created. However, under gcc 9.4.0, the "a-" prefix is not present.

    There is no documented difference in the behavior of the -M or -MD option in GCC 11 relative to GCC 9. These have been stable for a fairly long time, so I think this …

    I was expecting .d files without the "a-" prefix.

    … is a reasonable expectation. In fact, I think it’s so reasonable, especially in light of the documentation, that I’m inclined to guess that the issue is not as described in the question. Perhaps one or more additional command-line options were specified, or perhaps the source file name was not as claimed. This sort of thing might creep in under the radar if, for example, the build command were constructed with the help of make variables.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search