代码的目录结构如下:
$ 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!
网友评论