美文网首页
最简单的autotools例子

最简单的autotools例子

作者: louyang | 来源:发表于2020-10-14 16:43 被阅读0次

    代码的目录结构如下:

    $ tree
    ├── autogen.sh
    ├── configure.ac
    ├── Makefile.am
    └── src
        ├── hello-world.cpp
        └── Makefile.am
    

    各文件内容为:

    $ cat autogen.sh 
    #!/bin/sh
    autoreconf -i
    
    $ cat configure.ac
    #                                               -*- Autoconf -*-
    # Process this file with autoconf to produce a configure script.
    
    AC_PREREQ([2.69])
    AC_INIT(example-1-hello-world, 1.0, 576123579@qq.com)
    AC_CONFIG_SRCDIR([src/hello-world.cpp])
    AC_CONFIG_HEADERS([config.h])
    
    # Checks for programs.
    AC_PROG_CXX
    AM_INIT_AUTOMAKE
    AM_PROG_AS
    
    # Checks for libraries.
    # Checks for header files.
    # Checks for typedefs, structures, and compiler characteristics.
    # Checks for library functions.
    
    AC_OUTPUT(Makefile src/Makefile)
    
    $ cat Makefile.am 
    AUTOMAKE_OPTIONS = foreign
    SUBDIRS = src
    
    $ cat src/hello-world.cpp 
    #include <iostream>
    
    int main()
    {
        std::cout << "Hello World!" << std::endl;
        return 0;
    }
    
    $ cat src/Makefile.am 
    bin_PROGRAMS = helloworld
    helloworld_SOURCES = hello-world.cpp
    AM_CPPFLAGS = -std=c++11
    helloworld_LDADD = 
    

    编译运行:

    $ ./autogen.sh
    $ ./configure
    $ make
    $ src/helloworld 
    Hello World!
    

    相关文章

      网友评论

          本文标题:最简单的autotools例子

          本文链接:https://www.haomeiwen.com/subject/hbzjrktx.html