Skip to content

compiledb returns nothing when compiling headers with -x switch #140

@sleeptightAnsiC

Description

@sleeptightAnsiC

Let's say, I want to compile a header-only library. In this case the file extension would be something like *.h *.hpp *.hh , and in order to compile those I need to pass -x <lang> argument to the compiler (e.g. gcc -x c or g++ -x c++). Not doing so could trigger the compilation of pre-compiled-header, adding -x treats them as regular translation units.

So this seems like a valid use case. However, compiledb does not seem to recognize this pattern:

$ git clone https://github.com/nothings/stb.git
$ cd stb
$ echo "cc -x c -c ./stb_image.h -DSTB_IMAGE_IMPLEMENTATION" | compiledb --output -
[]

Notice that after changing the file name extension, the issue will disappear:

$ cp stb_image.h stb_image.c
$ echo "cc -x c -c ./stb_image.c -DSTB_IMAGE_IMPLEMENTATION" | compiledb --output -
[                                                                                                                                                                                                                                                              
 {                                                                                                                                                                                                                                                             
  "directory": "/tmp/stb",                                                                                                                                                                                                                                     
  "arguments": [                                                                                                                                                                                                                                               
   "cc",                                                                                                                                                                                                                                                       
   "-x",                                                                                                                                                                                                                                                       
   "c",                                                                                                                                                                                                                                                        
   "-c",                                                                                                                                                                                                                                                       
   "./stb_image.c",                                                                                                                                                                                                                                            
   "-DSTB_IMAGE_IMPLEMENTATION"                                                                                                                                                                                                                                
  ],                                                                                                                                                                                                                                                           
  "file": "./stb_image.c"                                                                                                                                                                                                                                      
 }                                                                                                                                                                                                                                                             
] 

Tested on version 0.10.7-3 installed from AUR (should be up-to-date with git master branch)

$ python --version
Python 3.13.7
$ uname -a
Linux MAL200424 6.16.3-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 23 Aug 2025 15:32:49 +0000 x86_64 GNU/Linux
$ cc --version
cc (GCC) 15.2.1 20250813

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions