2013-05-18 26 views
1

我正在編寫一個使用boost::asio來訪問串行端口的程序。根據文檔,當定義宏BOOST_ASIO_HAS_SERIAL_PORT時串行端口支持可用。由於這是一項要求,如果宏未定義,我希望我的配置腳本中止。autoconf:如何檢查#define的存在

我以爲我可以像下面這樣實現這一點:

AC_MSG_CHECKING([for serial port support in boost::asio]) 
AC_EGREP_CPP(yes_have_boost_asio_serial, [ 
#include <boost/asio.hpp> 
#ifdef BOOST_ASIO_HAS_SERIAL_PORT 
yes_have_boost_asio_serial 
#endif 
], [ 
    AC_MSG_RESULT([yes]) 
], [ 
    AC_MSG_RESULT([no]) 
    AC_ERROR([boost::asio must be compiled with serial port support enabled]) 
]) 

不幸的是,當我把這個,我得到生成的配置腳本時,一個奇怪的錯誤:

configure.ac:23: error: possibly undefined macro: BOOST_ASIO_HAS_SERIAL_PORT 
     If this token and others are legitimate, please use m4_pattern_allow. 
     See the Autoconf documentation. 

爲什麼autoconf在我的代碼中看到宏?關於m4_pattern_allow的文檔或多或少地表示,如果您必須使用它,出了問題,那麼我做錯了什麼?

+0

適用於我,沒有錯誤使用autoconf 2.69。 – ldav1s

回答

2

我結束了剛剛使用m4_pattern_allow,我想這與全尺寸的大寫符號看起來像autoconf應該處理的東西有關?

m4_pattern_allow([BOOST_ASIO_HAS_SERIAL_PORT]) 

AC_MSG_CHECKING([for serial port support in boost::asio]) 
...