And*_*zos 14 c linux gcc binutils
我正在尝试使用BFD库,所以我已经安装了包binutils-dev并且包括:
#include <bfd.h>
Run Code Online (Sandbox Code Playgroud)
和我打电话bfd_openr,并bfd_close从我的代码等等.
最近我升级了包,现在我从这里得到一个错误:
bfd.h:
/* PR 14072: Ensure that config.h is included first. */
#if !defined PACKAGE && !defined PACKAGE_VERSION
#error config.h must be included before this header
#endif
Run Code Online (Sandbox Code Playgroud)
......我应该包括config.h- 但我没有使用autoconf.
我是否包含错误的头文件?你怎么用binutils-dev?
这是一个演示程序:
#include <stdio.h>
#include <bfd.h>
int main()
{
bfd_init();
bfd* file = bfd_openr("a.out", 0);
if (!file)
return -1;
if (bfd_check_format(file, bfd_object))
printf("object file\n");
else
printf("not object file\n");
bfd_close(file);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
尝试编译并运行如下:
$ sudo apt-get install binutils-dev
$ gcc test.c
In file included from test.c:3:0:
/usr/include/bfd.h:37:2: error: #error config.h must be included before this header
Run Code Online (Sandbox Code Playgroud)
Mic*_*rny 12
那么,使用标题的最正确方法是在包中使用autotools.有些人只是固执,我认为你不能做太多.
另一种方法是通过定义它正在使用的宏来解决检查:
#define PACKAGE 1
#define PACKAGE_VERSION 1
Run Code Online (Sandbox Code Playgroud)
当然,如果您已经定义了这些,您可以将它们设置为一些合理的值,例如:
#define PACKAGE "your-program-name"
#define PACKAGE_VERSION "1.2.3"
Run Code Online (Sandbox Code Playgroud)
并将它们用于您的程序.你通常会在某些时候使用类似的东西来保持版本的一致性.
如果您使用符合标准的编译器,这应该足够了,因为__STDC__宏将被声明,一切都会好起来的.好吧,只要您使用的标头不需要更多autoconf生成的定义.
例如,如果你想使用plugin-api.h,你实际上必须处理检查stdint.h和inttypes.h...