Search code examples
gccmakefiledependenciesc-preprocessor

Why does gcc 11.3.0 append "a-" to dependency file name?


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 world\n");
  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.


Solution

  • 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.