我正在尝试使用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...that我应该包括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发布于 2012-08-01 04:59:41
嗯,使用头文件的最正确的方法是在你的包中使用自动工具。有些人就是很固执,我认为你对此无能为力。
另一种方法是通过定义正在使用的宏来绕过检查:
#define PACKAGE 1
#define PACKAGE_VERSION 1当然,如果您已经在定义它们,那么您也可以将它们设置为一些合理的值,例如:
#define PACKAGE "your-program-name"
#define PACKAGE_VERSION "1.2.3"并在你的程序中使用它们。您通常会在某些时候使用类似的东西来保持版本的一致性。
如果您使用的是符合标准的编译器,这应该就足够了,因为这样__STDC__宏就会被声明,一切都会正常进行。好吧,只要你使用的头文件不需要更多的autoconf生成的定义。
例如,如果你想使用plugin-api.h,你实际上必须处理对stdint.h和inttypes.h的检查...
https://stackoverflow.com/questions/11748035
复制相似问题