The autotools-unittest is a minimal starter kit when writing C++ library with autotools, google test and google mock.
C++ M4 Other
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.


The autotools-unittest is a minimal starter kit when writing C++ library with autotools, google test(gtest) and google mock(gmock). This include gtest-1.8.0 and gmock-1.8.0, so you can use those testing framework without installation.


  • Autoconf
  • Automake
  • Libtool


0. Download and extract

$ wget ""
$ tar xzf autotools-unittest-0.4.0.tar.gz

1. Change library name

Change package name from 'autotools-unittest' to your library name. (ex. mylib)

$ mv autotools-unittest-0.4.0 mylib
$ cd mylib
$ ./scripts/ mylib

* ./
* ./
* ./src/autotools-unittest/sample.cpp
* ./src/autotools-unittest/sample.h
* ./test/sample_test.cpp
* ./
* ./src/autotools-unittest

These files will be changed. Are you sure? [yes/NO]: yes

* ./ ... done.
* ./ ... done.
* ./src/autotools-unittest/sample.cpp ... done.
* ./src/autotools-unittest/sample.h ... done.
* ./test/sample_test.cpp ... done.
* ./ ... done.
* ./src/autotools-unittest ... done.

2. Build sample codes

$ ./
$ ./configure
$ make

3. Build unit tests and run

$ make check

4. Write your library


Check Coding style

You can use coding style checker(cpplint) if python is installed in your environment.

$ make check-style

If you would like to check coding style with cpplint's options, please use CPPLINT_OPTIONS variables like this.

$ make check-style CPPLINT_OPTIONS="--verbose=4"

Use advanced gtest options

You can use advanced gtest options via environment variables(GTEST_xxx).

For example, you can filter test cases as follows.

$ GTEST_FILTER="square.*" make check

For more information about advanced options, please see the following page.

Report coverage

You can use coverage reporting feature if lcov is installed in your environment.

$ make coverage
Successfully created coverage reports into ./coverage directory.

Please check "./coverage/index.html".

By default, source codes will be complied with no-optimization(-O0 option) to get more precise results.

If you would like to get coverage reports with optimization, please use COVERAGE_OPTFLAGS variables like this.

$ make coverage COVERAGE_OPTFLAGS="-O2"

Please take care that coverage reports with optimization results in unexpected one.

Build with clang or new gcc

Execute configure with CC, CXX variables (and GCOV if you measure coverage.)

For clang:

$ ./configure CC="clang" CXX="clang++" GCOV="gcov"

For gcc 5:

$ ./configure CC="gcc-5" CXX="g++-5" GCOV="gcov-5"

Not compile with C++11 mode

Edit and comment the following line. (Disable AX_CXX_COMPILE_STDCXX_11)

# Check for C++11 supports
#   ext: use extended mode (e.g. -std=gnu++11)
#   noext: use non-extended mode (e.g. -std=c++11)

And then, try again from executing

$ ./ && ./configure && make && make check

You can remove m4/ax_cxx_compile_stdcxx_11.m4. Please take care that "make dist" don't bundle not used m4 file.

Use pkg-config

Please do not forget to edit ( if you provide shared libraries. (By default, link libsample)

Libs: -L${libdir} -lsample