compiledb icon indicating copy to clipboard operation
compiledb copied to clipboard

compiledb for clang and/or MinGW GCC generates empty compile_commands.json

Open wireless-road opened this issue 5 years ago • 14 comments

Hi! Have pretty simple C project containing just one source file hello.c:

#include <stdio.h>

int main()
{
	printf("Hello world!\n");	 
	return 0;
}

here is Makefile for this project:

clang:
	@echo 'clangg'
	clang.exe -IC:\tools\MinGW\i686-w64-mingw32\include hello.c -v -o hello.exe

mingw:
	C:\tools\MinGW\bin\gcc.exe -IC:\tools\MinGW\i686-w64-mingw32\include hello.c -v -o hello.exe

I've compiledb installed by: pip install compiledb

So, when I'm trying to run compiledb make clang: It shows me following output:

clang version 9.0.0 (tags/RELEASE_900/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: c:\Program Files\LLVM\bin
 "c:\\Program Files\\LLVM\\bin\\clang.exe" -cc1 -triple x86_64-pc-windows-msvc19.24.28315 -emit-obj -mrelax-all -mincremental-linker-compatible -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello.c -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -momit-leaf-frame-pointer -v -resource-dir "c:\\Program Files\\LLVM\\lib\\clang\\9.0.0" -I "C:\\tools\\MinGW\\i686-w64-mingw32\\include" -internal-isystem "c:\\Program Files\\LLVM\\lib\\clang\\9.0.0\\include" -internal-isystem "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.24.28314\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\winrt" -fdebug-compilation-dir "C:\\cms_new\\cms_iot_sw_package\\sources\\iot\\hello\\src" -ferror-limit 19 -fmessage-length 210 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.24.28315 -fdelayed-template-parsing -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -faddrsig -o "C:\\Users\\ALMAZ~1.KHA\\AppData\\Local\\Temp\\hello-c576e2.o" -x c hello.c
clang -cc1 version 9.0.0 based upon LLVM 9.0.0 default target x86_64-pc-windows-msvc
#include "..." search starts here:
#include <...> search starts here:
 C:\tools\MinGW\i686-w64-mingw32\include
 c:\Program Files\LLVM\lib\clang\9.0.0\include
 C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include
 C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt
 C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared
 C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um
 C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt
End of search list.
 "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.24.28314\\bin\\Hostx64\\x64\\link.exe" -out:hello.exe -defaultlib:libcmt "-libpath:C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.24.28314\\lib\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.18362.0\\ucrt\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.18362.0\\um\\x64" -nologo "C:\\Users\\ALMAZ~1.KHA\\AppData\\Local\\Temp\\hello-c576e2.o"

But generated compile_commands.json contains just square brackets: []

Same if I try to compile by compiledb make mingw.

So is compiledb can work at Windows OS?

wireless-road avatar Jan 22 '20 13:01 wireless-road

I have the same error, but in my case, the file is completely empty.

EDIT: I fixed it by running a fake build, ie with the -n command. This could solve your problem.

TheGreatRambler avatar Jan 22 '20 14:01 TheGreatRambler

Unfortunately, -n didn't help. I run compiledb from source with enabled debug info and it shows me following:

## Processing build commands from <fdopen>
Line 1: Failed to parse build command [Details: (<class 'bashlex.tokenizer.MatchedPairError'>) unexpected EOF while looking for matching '`' (position 78)]. Ignoring: 'make: Entering directory `/c/sw_package/sources/iot/hello/src''
New command: C:\tools\MinGW\bin\gcc.exe -IC:\tools\MinGW\i686-w64-mingw32\include hello.c -v --debug -o hello.exe
Line 3: Failed to parse build command [Details: (<class 'bashlex.tokenizer.MatchedPairError'>) unexpected EOF while looking for matching '`' (position 77)]. Ignoring: 'make: Leaving directory `/c/sw_package/sources/iot/hello/src''
## Loaded compilation database with 0 entries from compile_commands.json
## Writing compilation database with 0 entries to compile_commands.json
## Done.

Seems that quote symbol before /c/sw_package breaks everything but when I run compiledb make mingw from command line I didn't see any Entering directory and Leaving directory messages at all. Can't understand how to fix that.

wireless-road avatar Jan 22 '20 14:01 wireless-road

Can't clang generate compile_commands.json files natively?

TheGreatRambler avatar Jan 22 '20 16:01 TheGreatRambler

I have the same issue, my compile_commands.json just show: []

misterb0407 avatar May 06 '20 16:05 misterb0407

Same with me. I am getting compile_commands.json with only [] in Windows

sonulohani avatar Jun 17 '20 07:06 sonulohani

I encountered the same error on MacOS 10.15. I fix this through using make | compiledb instead of compiledb make. See this Issue

J-keaper avatar Jun 30 '20 17:06 J-keaper

Same issue with me too.

I am working on a huge project that generally uses a couple of different compilers to compile for different embedded platforms, all on a remote ubuntu machine.

All I wanted to do is have a compilation db to get proper autocompletion, code jumping/navigation etc.

I exported the make -Bnwk output to a build.log, copied it to my local machine and used compiledb.exe --parse build.log and it didn't work. Also tried cat build.log | compiledb.exe for each of the following cases.

I tried removing all binary characters, removing the entire path of compilers and replacing them with just gcc/clang/CC & g++/clang++/CXX, no avail.

I keep getting just [] in my compiled_commands.json

I hope there is some workaround.

imran27 avatar Aug 06 '20 09:08 imran27

I ran into this Issue working under msys on a Windows host. As a python package compiledb relies on the standard python pathname processing built-ins. These, of course, do not handle the special pathname conventions Posix shell environments like MSYS or Cygwin use to represent Windows drive-letters.

As a result joining the current working dir and the filename path captured from make does not produce a correct legal windows pathname. This causes the check that the file corresponding to the joined pathname exists to fail(unless you've specifiied -S) no entry is generated. Even if you specify -S the pathnames are mostly mangled/useless.

I've created a PR (#110) with a small patch that fixes this. Feedback from folks using cygwin etc welcome!

andrewstevens-infineon avatar Nov 24 '20 14:11 andrewstevens-infineon

Same issue here. compiledb only produces a compile_commands.json that only contains [ ] when run in a build folder. Interestingly when I ran it at the project's root folder it produces a compile_commands.json file that contains an entry for the main.cpp file in there but not for .cpp files inside other folders.

Also I tried running compiledb on the same project inside WSL2 and it works perfectly.

AJigsawnHalo avatar Feb 25 '21 05:02 AJigsawnHalo

I also have this issue. Is there any way compiledb can support MSVC? I would love to see some sort of output after trying at least 5 diffirent ways to try to generate this illusive file.

aqilc avatar Dec 21 '22 04:12 aqilc

I noticed that compiledb puts in compilation database only the files which are at the root of the project, but not the files which are in subdirectories. I guess this could be because it does not handle properly windows' path separator \ ?

ericLemanissier avatar Jan 06 '23 15:01 ericLemanissier

I had the same issue. Removing the .exe after my compiler path worked for me.

You'll have to add it back in manually to the generated compile_commands.json after though.

Your makefile would become:

clang:
	@echo 'clangg'
	clang -IC:\tools\MinGW\i686-w64-mingw32\include hello.c -v -o hello.exe

mingw:
	C:\tools\MinGW\bin\gcc -IC:\tools\MinGW\i686-w64-mingw32\include hello.c -v -o hello.exe

Rixium avatar Mar 11 '23 05:03 Rixium