binutils / bfd。h希望配置。h ?

时间:2022-08-06 02:17:53

I'm trying to use the BFD library, and so I've installed package binutils-dev and have included:

我正在尝试使用BFD库,所以我已经安装了包binutils-dev,并包括:

#include <bfd.h>

and am calling bfd_openr and bfd_close and so on from my code.

我在代码中调用bfd_openr和bfd_close等等。

Recently I have upgraded packages and now I get an error from here:

最近我升级了包,现在我从这里得到一个错误:

bfd.h:

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 I should include config.h - but I am not using autoconf.

…我应该包括config。h -但是我没有使用autoconf。

Am I including the wrong header file? How are you supposed to use binutils-dev?

我是否包括了错误的头文件?你应该如何使用binutils-dev?

Here is a demo program:

这是一个演示程序:

#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;
}

try to compile and run as follows:

尝试编译和运行如下:

$ 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

1 个解决方案

#1


9  

Well, the most correct way of using the header is to use autotools in your package as well. Some people are simply stubborn and I don't think you can do much about it.

使用header最正确的方法是在包中使用autotools。有些人很固执,我认为你对此无能为力。

An alternative is to work-around the check, by defining the macros it is using:

另一种方法是通过定义它所使用的宏来进行检查。

#define PACKAGE 1
#define PACKAGE_VERSION 1

Of course, if you are already defining those, you may as well set them to some reasonable values like:

当然,如果你已经定义了这些,你可以把它们设置成一些合理的值,比如:

#define PACKAGE "your-program-name"
#define PACKAGE_VERSION "1.2.3"

and use them for your program. You'll usually going to use something like that anyway at some point to keep the versions consistent.

并将它们用于您的程序。你通常会在某个时刻使用类似的东西来使版本保持一致。

This should be enough if you're using a standards-compliant compiler because then the __STDC__ macro will be declared and everything will go on just fine. Well, as long as the headers you're using won't require more autoconf-generated defines.

如果您使用符合标准的编译器,这就足够了,因为__STDC__宏将被声明,一切都会正常运行。只要您使用的头文件不需要更多的autoconf生成的定义。

For example, if you wanted to use plugin-api.h, you'd actually have to handle checking for stdint.h and inttypes.h...

例如,如果您想要使用plugin-api。h,你必须要负责检查stdint。h和inttypes.h……

#1


9  

Well, the most correct way of using the header is to use autotools in your package as well. Some people are simply stubborn and I don't think you can do much about it.

使用header最正确的方法是在包中使用autotools。有些人很固执,我认为你对此无能为力。

An alternative is to work-around the check, by defining the macros it is using:

另一种方法是通过定义它所使用的宏来进行检查。

#define PACKAGE 1
#define PACKAGE_VERSION 1

Of course, if you are already defining those, you may as well set them to some reasonable values like:

当然,如果你已经定义了这些,你可以把它们设置成一些合理的值,比如:

#define PACKAGE "your-program-name"
#define PACKAGE_VERSION "1.2.3"

and use them for your program. You'll usually going to use something like that anyway at some point to keep the versions consistent.

并将它们用于您的程序。你通常会在某个时刻使用类似的东西来使版本保持一致。

This should be enough if you're using a standards-compliant compiler because then the __STDC__ macro will be declared and everything will go on just fine. Well, as long as the headers you're using won't require more autoconf-generated defines.

如果您使用符合标准的编译器,这就足够了,因为__STDC__宏将被声明,一切都会正常运行。只要您使用的头文件不需要更多的autoconf生成的定义。

For example, if you wanted to use plugin-api.h, you'd actually have to handle checking for stdint.h and inttypes.h...

例如,如果您想要使用plugin-api。h,你必须要负责检查stdint。h和inttypes.h……