我正在尝试使用 BFD 库,所以我安装了软件包 binutils-dev
并包含:
#include <bfd.h>
我正在从我的代码中调用 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
...我应该包括 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;
}
尝试编译运行如下:
$ 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
最佳答案
嗯,使用 header 的最正确方法是在您的包中也使用 autotools。有些人就是固执,我认为您无能为力。
另一种方法是通过定义它正在使用的宏来解决检查问题:
#define PACKAGE 1
#define PACKAGE_VERSION 1
当然,如果您已经定义了这些,您也可以将它们设置为一些合理的值,例如:
#define PACKAGE "your-program-name"
#define PACKAGE_VERSION "1.2.3"
并将它们用于您的程序。您通常会在某个时候使用类似的东西来保持版本一致。
如果您使用的是符合标准的编译器,这应该足够了,因为那时将声明 __STDC__
宏,一切都会正常进行。好吧,只要您使用的 header 不需要更多 autoconf 生成的定义。
例如,如果您想使用 plugin-api.h
,您实际上必须处理对 stdint.h
和 inttypes.h 的检查
...
关于c - binutils/bfd.h 现在想要 config.h 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11748035/