2

我将所有内容从 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 中定义的一些数据结构。知道我做错了什么吗?

4

2 回答 2

6

当您将所有内容从 include/git2 复制到 /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 文档中的搜索路径

于 2013-06-04T06:08:33.520 回答
1

作为记录,您应该使用构建系统来安装标头。这些标头本身不会被包含在内。如果你想使用 libgit2,你应该包括git2.h.

于 2013-06-04T13:50:11.703 回答