简体   繁体   English

如何自动制作C源文件

[英]How to automake C source files

I have a file cmdscan.c that contains just a function and a struct. 我有一个文件cmdscan.c,其中仅包含一个函数和一个结构。 My main program hsh.c uses the function and struct from cmdscan.c. 我的主程序hsh.c使用cmdscan.c中的函数和结构。 I followed the instructions on my professor's pdf exactly but it will not work. 我完全按照教授pdf上的说明进行操作,但无法使用。 Even if I edit something save and run make it says there is nothing to be done. 即使我编辑保存并运行的内容,也不会执行任何操作。 And when I use make distcheck I get an error saying it can't find hsh.c. 当我使用make distcheck时,出现错误,提示找不到hsh.c。

This is what my directory contains: 这是我的目录包含的内容:

Makefile.am: Makefile.am:

    bin_PROGRAMS = hsh
    hsh_SOURCES = hsh.c cmdscan.c

configure.in: configure.in:

    AC_INIT(hsh.c)
    AM_INIT_AUTOMAKE(hsh,1.0)
    AC_PROG_CC
    AC_PROG_INSTALL
    AC_OUTPUT(Makefile)

I made sure to use tabs. 我确保使用标签。 Then I run the commands: 然后运行命令:

aclocal
autoconf
touch README AUTHORS NEWS ChangeLog
automake -a
configure
make

Note: when I run "configure" it says command not found. 注意:当我运行“配置”时,它说找不到命令。 But I can run ./configure so that's what I did. 但是我可以运行./configure,这就是我所做的。

When I do last command "make" I get: 当我执行最后一个命令“ make”时,我得到:

make: Nothing to be done for `all'.

Even if I edit something and save it. 即使我编辑并保存了一些内容。 So when I run 所以当我跑步

make distcheck

I get: 我得到:

configure: error: cannot find sources (hsh.c) in ..
make: *** [distcheck] Error 1

If I run: 如果我运行:

gcc cmdscan.c hsh.c -o hsh

It works. 有用。

You have some errors like: 您有一些错误,例如:

AC_INIT(hsh.c), AM_INIT_AUTOMAKE(hsh,1.0) instead use for example:
AC_INIT([hsh],[1.0])
AM_INIT_AUTOMAKE([1.14])

where "1.14" is my automake version, you can see this: automake --version 其中“ 1.14”是我的自动制作版本,您可以看到以下内容:automake --version

If you need a quick tutorial see: http://embelinux.blogspot.de/2013/09/autotools1-hola-mundo-la-autotools.html If you need strong documentation run: apt-get install autoconf (see /usr/share/doc/autoconf-doc) and download http://www.gnu.org/software/automake/manual/automake.pdf 如果需要快速教程,请参见: http : //embelinux.blogspot.de/2013/09/autotools1-hola-mundo-la-autotools.html如果需要强大的文档,请运行:apt-get install autoconf(请参见/ usr /共享/ doc / autoconf-doc)并下载http://www.gnu.org/software/automake/manual/automake.pdf

AC_INIT (package, version, [bug-report], [tarname], [url])

Process any command-line arguments and perform initialization and verification. 处理任何命令行参数并执行初始化和验证。 Set the name of the package and its version. 设置软件包名称及其版本。 These are typically used in '--version' support, including that of configure. 这些通常用于'--version'支持,包括configure的支持。 The optional argument bug-report should be the email to which users should send bug reports. 可选参数bug-report应该是用户应向其发送错误报告的电子邮件。 The package tarname differs from package: the latter designates the full package name (eg, 'GNU Autoconf'), while the former is meant for distribution tar ball names (eg, 'autoconf'). 程序包的tarname与程序包不同:后者指定完整的程序包名称(例如,“ GNU Autoconf”),而前者用于分发tar球名称(例如,“ autoconf”)。 It defaults to package with 'GNU ' stripped, lower-cased, and all characters other than alphanumerics and underscores are changed to '-'. 默认情况下,打包时将'GNU'剥离,小写,并且除字母数字和下划线以外的所有字符均更改为'-'。 If provided, url should be the home page for the package. 如果提供,则url应该是软件包的主页。 The arguments of AC_INIT must be static, ie, there should not be any shell compu- tation, quotes, or newlines, but they can be computed by M4. AC_INIT的参数必须是静态的,即,不应有任何Shell运算,引号或换行符,但它们可以由M4计算。 This is because the package information strings are expanded at M4 time into several contexts, and must give the same text at shell time whether used in single-quoted strings, double-quoted strings, quoted here-documents, or unquoted here-documents. 这是因为程序包信息字符串在M4时扩展为多个上下文,并且无论在单引号字符串,双引号字符串,在此引用的文档还是在未引用的文档中使用,都必须在Shell时给出相同的文本。 It is permissible to use m4_esyscmd or m4_esyscmd_s for computing a version string that changes with every commit to a version control system (in fact, Autoconf does just that, for all builds of the development tree made between releases). 允许使用m4_esyscmd或m4_esyscmd_s计算随版本控制系统的每次提交而变化的版本字符串(实际上,对于在两次发行之间进行的所有开发树构建,Autoconf都会这样做)。

AM_INIT_AUTOMAKE([OPTIONS])

Runs many macros required for proper operation of the generated Makefiles. 运行生成的Makefile的正确操作所需的许多宏。 Today, AM_INIT_AUTOMAKE is called with a single argument: a space-separated list of Automake options that should be applied to every Makefile.am in the tree. 今天,使用单个参数调用AM_INIT_AUTOMAKE:以空格分隔的Automake选项列表,应将其应用于树中的每个Makefile.am。 The effect is as if each option were listed in AUTOMAKE_OPTIONS (see Chapter 17 [Options], page 117). 效果就像每个选项都列在AUTOMAKE_OPTIONS中一样(请参见第17章[选项],第117页)。 This macro can also be called in another, deprecated form: AM_INIT_ AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE]). 也可以以另一种不建议使用的形式调用此宏:AM_INIT_ AUTOMAKE(PACKAGE,VERSION,[NO-DEFINE])。 In this form, there are two required arguments: the package and the version number. 在此格式中,有两个必需的参数:程序包和版本号。 This usage is mostly obsolete because the package and version can be obtained from Autoconf's AC_INIT macro. 因为可以从Autoconf的AC_INIT宏获取软件包和版本,所以这种用法通常已经过时了。 However, differently from what happens for AC_INIT invocations, this AM_INIT_AUTOMAKE invocation supports shell variables' expansions in the PACKAGE and VERSION arguments, and this can be still be useful in some selected situations. 但是,与AC_INIT调用不同,此AM_INIT_AUTOMAKE调用在PACKAGE和VERSION参数中支持shell变量的扩展,这在某些选定的情况下仍然有用。 Our hope is that future Autoconf versions will improve their support for package versions defined dynamically at configure runtime; 我们希望将来的Autoconf版本将改进它们对在配置运行时动态定义的软件包版本的支持。 when (and if) this happens, support for the two-args AM_INIT_AUTOMAKE invocation will likely be removed from Automake. 当(如果发生)这种情况时,很可能会从Automake中删除对两个参数AM_INIT_AUTOMAKE调用的支持。

The issue ended up being that I had to change configure.in to configure.ac. 问题最终是我必须将configure.in更改为configure.ac。 Then I had to add another parameter to my open file statements, 0666 . 然后,我必须在打开的文件语句0666添加另一个参数。 After that all seems to be well and it compiles and allows me to create a package. 之后,一切似乎都很好,它可以编译并允许我创建一个包。 The pdf gave no such information -_-. pdf没有提供此类信息-_-。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM