How do I use C headers from libgit2 without getting this error?

一笑奈何 提交于 2019-12-24 02:17:37

问题


I took everything from include/git2 to /usr/include, then tried compiling the following program:

#include <stdio.h>
#include <repository.h>

int main(void) {
    puts("Hello, world!");
    return 0;
}

When I compile this with GCC, I get the following error:

maxwell@UNIX-PC:~$ gcc ok.c
In file included from /usr/include/common.h:16:0,
                 from /usr/include/repository.h:10,
                 from ok.c:2:
/usr/include/inttypes.h:33:2: error: #error "Use this header only with Microsoft Visual C++ compilers!"
In file included from /usr/include/inttypes.h:46:0,
                 from /usr/include/common.h:16,
                 from /usr/include/repository.h:10,
                 from ok.c:2:
/usr/include/stdint.h:33:2: error: #error "Use this header only with Microsoft Visual C++ compilers!"
In file included from /usr/include/inttypes.h:46:0,
                 from /usr/include/common.h:16,
                 from /usr/include/repository.h:10,
                 from ok.c:2:
/usr/include/stdint.h:89:30: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int64_t’
/usr/include/stdint.h:90:30: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uint64_t’
/usr/include/stdint.h:101:1: error: unknown type name ‘uint64_t’
/usr/include/stdint.h:111:1: error: unknown type name ‘uint64_t’
/usr/include/stdint.h:124:1: error: unknown type name ‘uint64_t’
In file included from /usr/include/common.h:16:0,
                 from /usr/include/repository.h:10,
                 from ok.c:2:
/usr/include/inttypes.h:282:1: error: unknown type name ‘_inline’
/usr/include/inttypes.h:284:11: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__cdecl’
/usr/include/inttypes.h:284:11: error: unknown type name ‘__cdecl’

I see the error that says only to use inttypes.h only with Visual Studio, so how do I call repository.h from a program compiled with GCC? I really want to use some data structures defined in repository.h. Any idea what I am doing wrong?


回答1:


For the record, you should use the build system to install the headers. These headers aren't made to be included themselves. If you want to use libgit2, you should include git2.h.




回答2:


It seems that some header files were overwritten when you copied eveything from include/git2 to /usr/include.

In file included from /usr/include/common.h:16:0,
                 from /usr/include/repository.h:10,
                 from ok.c:2:
/usr/include/inttypes.h:33:2: error: #error "Use this header only with Microsoft Visual   C++ compilers!"

The right approach is to use gcc's -Iinclude_path option to include the other header files, and use "-D macro_def" to define the macros that are to be used with the preprocessor.

gcc -I repository_h_path  -D some_macro  ok.c

You might want to refer to search path in gcc documentation.



来源:https://stackoverflow.com/questions/16910801/how-do-i-use-c-headers-from-libgit2-without-getting-this-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!