GNU autotool:没有规则可作为目标 [英] GNU autotool:No rule to make target

查看:61
本文介绍了GNU autotool:没有规则可作为目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在堆栈溢出中的第一个问题!

my first question in stack overflow!

快速概述:我使用自动工具生成C程序.当我使用 make 命令时,遇到错误:

Quick overview of my question: I use autotool to generate a C program. When I use make command, I meet the error:

No rule to make target `../lib_foo/libfoo.a', needed by `mistery_foo'.  Stop.

我的问题的详细信息:

我正在做老师的作业,在该作业中,我应该使用GNU autotool 生成一个非常简单的C程序.

I am doing an assignment of my teacher, in which I should use GNU autotool to generate a very simple C program.

文件结构:/project:main,lib_foo,Makefile.am,configure.ac

File structure: /project: main, lib_foo, Makefile.am, configure.ac

/project/main:main.c,main.h,Makefile.am

/project/main: main.c, main.h, Makefile.am

/project/lib_foo:foo.c,foo.h,Makefile.am

/project/lib_foo: foo.c, foo.h, Makefile.am

以下是我为configure.ac和makefile.am编写的内容:

Following is what I write for configure.ac and makefile.am:

I."project/configure.ac" :

AC_PREREQ([2.67])
AC_INIT([project1],[0.01],[cwentai01@gmail.com])
AM_INIT_AUTOMAKE([1.9 foreign])
AC_CONFIG_SRCDIR([./lib_foo/foo.c])
AC_CONFIG_HEADERS([config.h])
AC_PROG_CC
AC_PROG_RANLIB
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <mistery.h>]],\
                [[ mistery_value(1);]])],\
                [AC_DEFINE([MISTERY_VALUE_ONEPARAM], [],[CONSTANT])],[])
AC_SEARCH_LIBS([mistery_value],[magic vadoo mistery],[],[AC_MSG_ERROR([Libraries (mistery, magic, vadoo) not found])])
AC_CONFIG_FILES([Makefile  lib_foo/Makefile main/Makefile])
AC_OUTPUT 

P.S.AC_COMPLIE_IFELSE用于判断函数mistery_value()中参数的数量.我认为这与错误无关.

P.S. the AC_COMPLIE_IFELSE is used to judge the number of the parameters in function mistery_value(). I think it has nothing to do with the error.

II. project/Makefile.am :

SUBDIRS = main lib_foo 

III. project/main/Makefile.am

LDADD = ../lib_foo/libfoo.a
mydir = ../uselessbin
my_PROGRAMS = mistery_foo
mistery_foo_SOURCES = main.c main.h
mistery_foo_LDADD = ../lib_foo/libfoo.a

IV. project/lib_foo/Makefile.am

noinst_LIBRARIES = libfoo.a
libfoo_a_SOURCES = foo.c foo.h

然后按命令顺序运行:

>cd project
> aclocal
> autoheader
> automake -a
> autoconf
> ./configure
> make
> make install
> ./uselessbin/mistery_foo

当我运行 make 命令时,出现错误:

When I run make command, I got the error:

No rule to make target `../lib_foo/libfoo.a', needed by `mistery_foo'.  Stop.

我想问题可能是我没有正确安装 libfoo.a .但是库 libfoo.a 不应安装,而只能编译,因此我必须在lib_foo/Makefile.am中使用'noinst_'.这就是为什么我被困在这里.

I suppose the problem may be that I don't have libfoo.a properly installed. But the library libfoo.a should not be installed but only compiled so I have to use 'noinst_' in lib_foo/Makefile.am. That's why I get stucked here.

任何答案将不胜感激.感谢您的帮助!

Any answers will be appreciated. Thanks for your help!

推荐答案

问题是您使用的是递归自动制作,在这种情况下,跨越目录路径的依赖项将无法解析为其他规则: main/Makefile.am 不知道如何在 lib_foo 中创建目标.

The problem is that you're using recursive automake, and in this case, dependencies crossing directory paths will just not resolve to extra rules: main/Makefile.am does not know how to make targets in lib_foo.

快速解决方法是将顶级 Makefile.am 中的 SUBDIRS 声明更改为:

The quick fix up is to change your SUBDIRS declaration in the top-level Makefile.am to:

SUBDIRS = lib_foo main

这样,仅在构建 lib_foo 及其目标之后,才能构建 main/mystery_foo .当然,这不允许您仅在 main/中进行 make 并使之起作用.

This way main/mystery_foo will only be built after lib_foo and its targets are built. Of course this does not allow you to just make in main/ and have it work.

上一篇文章中的另一个建议是使用非递归自动制作正确的解决方案,因为这样就可以从单个 Makefile.am 中解析所有依赖项.

The other suggestion from the previous post, to use non-recursive automake is a more proper solution, because then all the dependencies can be resolved from a single Makefile.am.

这篇关于GNU autotool:没有规则可作为目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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