Ale*_*lex 2 c linux git libgit2
我把所有东西从include/git2带到/ usr/include,然后尝试编译以下程序:
#include <stdio.h>
#include <repository.h>
int main(void) {
puts("Hello, world!");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我用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’
Run Code Online (Sandbox Code Playgroud)
我看到的错误仅表示只使用Visual Studio中的inttypes.h,那么如何从使用GCC编译的程序中调用repository.h?我真的想使用repository.h中定义的一些数据结构.知道我做错了什么吗?
当您将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!"
Run Code Online (Sandbox Code Playgroud)
正确的方法是使用gcc的-Iinclude_path选项来包含其他头文件,并使用"-D macro_def"来定义要与预处理器一起使用的宏.
gcc -I repository_h_path -D some_macro ok.c
Run Code Online (Sandbox Code Playgroud)
您可能希望在gcc文档中引用搜索路径.