在MinGW上使用gnulib入门并且对自动工具不熟悉(足够) [英] Getting started with gnulib on MinGW and not familiar (enough) with autotools

查看:264
本文介绍了在MinGW上使用gnulib入门并且对自动工具不熟悉(足够)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些C语言代码是为Linux编写的,它依赖于sockets和arpa/inet.h以及libusb.h,我想在MinGW下为Windows编译它. (请注意,当前项目只有一个非常简单的Makefile,完全不依赖自动工具).

I've got some C code that was written for Linux and relies on sockets and arpa/inet.h as well as libusb.h and I want to compile this for Windows under MinGW. (Note that the current project just has a very simple Makefile and doesn't rely on autotools at all).

使用gnulib似乎是在MinGW下为Windows进行编译的一个好方法,我已经朝这个方向开始,但是似乎如果您对自动工具不太熟悉,您会发现深杂草真的很快.

It looks like using gnulib would be a good way to be able to compile this for Windows under MinGW and I've started out in that direction, but it seems that if you're not very familiar with autotools you get into the deep weeds really quickly.

这就是我尝试过的:

$ gnulib-tool --import getsockname,getsockopt,setsockopt,socket,socketlib,sockets,socklen,sys_socket,arpa_inet,inet_ntop,inet_pton,netinet_in

它运行并在最后给出以下消息:

It runs and gives me the following message at the end:

Don't forget to
  - add "lib/Makefile" to AC_CONFIG_FILES in ./configure.ac,
  - mention "lib" in SUBDIRS in Makefile.am,
  - mention "-I m4" in ACLOCAL_AMFLAGS in Makefile.am,
  - mention "m4/gnulib-cache.m4" in EXTRA_DIST in Makefile.am,
  - invoke gl_EARLY in ./configure.ac, right after AC_PROG_CC,
  - invoke gl_INIT in ./configure.ac.

好吧,我既没有configure.ac也没有Makefile.am,所以我按照以下说明创建了它们:

Ok, I had no configure.ac nor a Makefile.am, so I created them as follows (as per the instructions above):

$ cat Makefile.am
SUBDIRS = lib
ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = m4/gnulib-cache.m4

然后...

$ cat configure.ac
AC_INIT([configure.ac])
AC_CONFIG_FILES([lib/Makefile])
AC_PROG_CC
gl_EARLY
gl_INIT

现在,此时,gnulib文档似乎假定您对自动工具非常熟悉,因此他们省略了接下来需要使用自动工具进行操作的所有说明.

Now at this point, the gnulib docs seem to assume that you're intimately familiar with autotools, so they leave out all of the instructions for what you need to do with autotools next.

从阅读各种论坛后我发现,看来下一步应该运行:

From what I've been able to figure out from reading various forums, it seems that the next steps are to run:

$ aclocal
$ autoconf
$ automake
$ configure

但是...当我运行自动制作时,我得到了:

However... when I ran automake I got:

$ automake
configure.ac: no proper invocation of AM_INIT_AUTOMAKE was found.
configure.ac: You should verify that configure.ac invokes AM_INIT_AUTOMAKE,
configure.ac: that aclocal.m4 is present in the top-level directory,
configure.ac: and that aclocal.m4 was recently regenerated (using aclocal).
lib/Makefile.am:30: library used but `RANLIB' is undefined
lib/Makefile.am:30:   The usual way to define `RANLIB' is to add  `AC_PROG_RANLIB

' lib/Makefile.am:30:再次configure.ac' and run autoconf'.

' lib/Makefile.am:30: to configure.ac' and runautoconf' again.

嗯...好吧,这可能只是我的Makefile.am中缺少的一些东西(因为我不确定要进入Makefile.am中的内容)...所以回去一步...我应该能够运行上面在autoconf步骤中创建的配置文件:

Hmmm... Ok that's probably just some stuff I'm missing in my Makefile.am (because I'm not entirely sure what should go into a Makefile.am)... so going back a step... I should be able to run the configure file that got created above in the autoconf step:

$ ./configure

checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.exe
checking for suffix of executables... .exe
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
./configure: line 2497: gl_EARLY: command not found
./configure: line 2498: gl_INIT: command not found
rm: cannot lstat `conftest.exe': Permission denied

从我通过谷歌搜索所阅读的内容来看,似乎gl_EARLY和gl_INIT应该由添加到Makefile.am文件中的行来处理(ACLOCAL_AMFLAGS = -I m4),但是在这一点上我还不是完全确定我在正确执行此自动工具部分.有人可以指出我在做什么错吗?

From what I've read by googling around it seems like the gl_EARLY and gl_INIT should be take care of by the line added to the Makefile.am file ( ACLOCAL_AMFLAGS = -I m4), but at this point I'm not entirely sure that I'm doing the autotools part of this correctly. Can anyone point out what I'm doing wrong here?

推荐答案

  1. AC_CONFIG_MACRO_DIR([m4])添加到configure.ac,它将在m4目录中找到gnulib宏
  2. 添加AM_INIT_AUTOMAKE
  3. AC_CONFIG_FILES不仅应包含gnulib Makefile,还应包含您的Makefile
  4. 您可以通过一次调用autoreconf
  5. 来重新生成所有内容
  1. Add AC_CONFIG_MACRO_DIR([m4]) to configure.ac and it will find gnulib macros in m4 directory
  2. Add AM_INIT_AUTOMAKE
  3. AC_CONFIG_FILES should contain not only gnulib Makefile, but your Makefile too
  4. You can regenerate all stuff with single call to autoreconf

这篇关于在MinGW上使用gnulib入门并且对自动工具不熟悉(足够)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆