justmao945 / vim-clang

Clang completion plugin for vim
ISC License
357 stars 47 forks source link

-include not work in .clang #136

Open amir28 opened 4 years ago

amir28 commented 4 years ago

Hello, First of all l have to appreciate all contributes who working on this project. I'm working on a project that written in c and GTK library. so I need to add extra option to the compiler that I use. according the this link I have to compile my code by:

gcc `pkg-config --cflags gtk+-3.0` -o example-1 example-1.c `pkg-config --libs gtk+-3.0`

so I think to get completion in vim-clang my .clang should be contain including ../config.h and the pkg-config --cflags gtk+-3.0 output:

-include ../config.h
-pthread
-I/usr/include/gtk-3.0
-I/usr/include/at-spi2-atk/2.0
-I/usr/include/at-spi-2.0
-I/usr/include/dbus-1.0
-I/usr/lib/x86_64-linux-gnu/dbus-1.0/include
-I/usr/include/gtk-3.0
-I/usr/include/gio-unix-2.0
-I/usr/include/cairo
-I/usr/include/pango-1.0
-I/usr/include/fribidi
-I/usr/include/harfbuzz
-I/usr/include/atk-1.0
-I/usr/include/cairo
-I/usr/include/pixman-1
-I/usr/include/uuid
-I/usr/include/freetype2
-I/usr/include/libpng16
-I/usr/include/gdk-pixbuf-2.0
-I/usr/include/libmount
-I/usr/include/blkid
-I/usr/include/glib-2.0
-I/usr/lib/x86_64-linux-gnu/glib-2.0/include

but after get completion by Ctrl-X Ctrl-O I get below error:

main.c:18:10: fatal error: 'config.h' file not found                                                                                                   
#include <config.h>                                                                                                                                    
         ^~~~~~~~~~                                                                                                                                    
 ClangDiagnostics@1[-]

my config.h exist in ../config.h

$ cat ../config.h
/* config.h.  Generated from config.h.in by configure.  */
/* config.h.in.  Generated from configure.ac by autoheader.  */

/* DBUS version. */
/* #undef DBUS_VERSION */

/* Define if DBUS support is enabled */
...

I use Ubuntu 20.04 and neovim v0.4.3

smekkley commented 4 years ago

I can't give you a solution but for relative path, I'd do, #include "config.h", include the whole directory. At least that's what most people do.

amir28 commented 4 years ago

I can't give you a solution but for relative path, I'd do, #include "config.h", include the whole directory. At least that's what most people do.

Yes, for workaround I can include whole ../ directory but I just wanted report this bug to I have done something for this project :)

smekkley commented 4 years ago

I've never seen a project that does include by file in gcc and then include as <> instead of "". I'm curious what the project is, if it's opensource. I've seen normal include like #include "../config.h", no include needed from the compiler.

amir28 commented 4 years ago

I've never seen a project that does include by file in gcc and then include as <> instead of "". I'm curious what the project is, if it's opensource. I've seen normal include like #include "../config.h", no include needed from the compiler.

Incidentally, I never seen a project use "" instead of <> :-) an example is mate-panel https://github.com/mate-desktop/mate-panel/blob/master/mate-panel/panel.c

smekkley commented 4 years ago

What I meant was to use <> AND include files when it's not in include path and add it in gcc.

haha. last commit seem to did that, very strange indeed.