1
votes

I have a C++ project and I'm trying to figure out how to get autotools to include the -lboost_unit_test_framework flag dynamically during the build process. If I add it and compile manually using g++ it builds, it's just missing the flag when setting up the makefiles using autotools.

Also, when running ./configure it returns:
./configure: line 3113: AX_BOOST_UNIT_TEST_FRAMEWORK: command not found

My configure.ac:

AC_PREREQ([2.69])
AC_INIT([project], [0.1.0], [[email protected]])
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([src/main.cpp])
AC_CONFIG_HEADERS([config.h])

# Checks for programs.
AC_PROG_CXX

# Checks for libraries.
AX_BOOST_UNIT_TEST_FRAMEWORK

# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.

AC_CONFIG_FILES([Makefile
                 src/Makefile
                 test/Makefile])
AC_OUTPUT
1

1 Answers

4
votes

I figured it out, the macro is undefined unless you download it from the autoconf-archive. I placed it in my project here project/m4.

Also, you have to tell configure.ac where to find them:

...
AC_CONFIG_HEADERS([config.h])

AC_CONFIG_MACRO_DIR([m4]) # << Add this line

# Checks for programs.
AC_PROG_CXX
...

Update:

Once I got this working, to get make check to execute the tests, I had to:

  1. Add this to the project/test/Makefile.am:

    check_PROGRAMS = program_tests
    program_tests_CPPFLAGS = -I../src/ ${BOOST_CPPFLAGS}
    program_tests_LDFLAGS = ${BOOST_LDFLAGS}
    program_wallet_tests_LDADD = ${BOOST_UNIT_TEST_FRAMEWORK_LIB}
    program_wallet_tests_SOURCES = runner.cpp main_tests.cpp
    
  2. Add this line to the main project/Makefile.am: TESTS = test/program_tests