【问题标题】:How to add boost unit test framework in autotools C++如何在 autotools C++ 中添加 boost 单元测试框架
【发布时间】:2019-01-16 08:25:02
【问题描述】:

我有一个 C++ 项目,我正在尝试弄清楚如何让自动工具在构建过程中动态包含 -lboost_unit_test_framework 标志。如果我添加它并使用它构建的g++ 手动编译,那么在使用 autotools 设置 makefile 时它只是缺少标志。

另外,当运行./configure 时,它会返回:
./configure: line 3113: AX_BOOST_UNIT_TEST_FRAMEWORK: command not found

我的 configure.ac:

AC_PREREQ([2.69])
AC_INIT([project], [0.1.0], [example@example.com])
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

【问题讨论】:

    标签: c++ autotools automake


    【解决方案1】:

    我想通了,除非你从autoconf-archive 下载宏,否则宏是未定义的。我把它放在我的项目中project/m4

    另外,您必须告诉configure.ac 在哪里可以找到它们:

    ...
    AC_CONFIG_HEADERS([config.h])
    
    AC_CONFIG_MACRO_DIR([m4]) # << Add this line
    
    # Checks for programs.
    AC_PROG_CXX
    ...
    

    更新:

    一旦我得到这个工作,让make check 执行测试,我必须:

    1. 将此添加到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. 将此行添加到主project/Makefile.amTESTS = test/program_tests

    【讨论】:

    • 我很高兴你知道了。对于未来的读者,这里的一个关键线索是您要使用的宏的名称以AX_ 开头。这是一个确定的信号,表明它不是由 Autoconf 发行版本身提供的,并且可能表明该宏可从 Autoconf 存档中获得。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-10
    • 1970-01-01
    • 2011-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多