如何在不收到此错误的情况下使用libgit2中的C头文件?

时间:2013-06-04 06:00:24

标签: c linux git libgit2

我从include / git2到/ usr / include,然后尝试编译以下程序:

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

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

当我使用GCC编译时,我收到以下错误:

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’

我看到的错误仅表示只使用Visual Studio的inttypes.h,那么如何从使用GCC编译的程序中调用repository.h?我真的想使用repository.h中定义的一些数据结构。知道我做错了吗?

2 个答案:

答案 0 :(得分:6)

当您从include / git2复制eveything到/ 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!"

正确的方法是使用gcc的-Iinclude_path选项来包含其他头文件,并使用“-D macro_def”来定义要与预处理器一起使用的宏。

gcc -I repository_h_path  -D some_macro  ok.c

您可能需要在gcc文档中引用search path

答案 1 :(得分:1)

对于记录,您应该使用构建系统来安装标头。这些标题不会自己包含在内。如果你想使用libgit2,你应该包括git2.h