Howto add a link to a library in autoconf configure script / makefile

耗尽温柔 提交于 2019-12-03 05:19:17

You need to add the relevant -l flag to AM_LDFLAGS in Makefile.am; e.g.:

AM_LDFLAGS = -lboost_system-mt

Note that Boost libraries generally end in a suffix—a sequence of letters that indicates the build configuration. In the above example, the suffix is -mt. This could be different in your installation (though the -mt variant is commonly available on POSIXy systems, IME).

I do something like this:

AM_LDFLAGS = -lboost_system$(BOOST_LIB_SUFFIX)

BOOST_LIB_SUFFIX is a precious variable (see AC_ARG_VAR) that defaults to -mt.

Alexander Patrikalakis

Use ax_cxx_check_lib.m4 because boost_system does not have any extern "C" symbols (unmangled names) that can be checked with AC_CHECK_LIB:

http://ac-archive.sourceforge.net/guidod/ax_cxx_check_lib.m4

Download the file above and name it acinclude.m4, and put it in the m4 folder in your project root.

In configure.ac:

AC_LANG_PUSH([C++])

AX_CXX_CHECK_LIB([boost_system-mt],[boost::system::generic_category()],[BOOST_LIB_SUFFIX="-mt"],[BOOST_LIB_SUFFIX=""])

AC_LANG_POP([C++])

AC_SUBST(BOOST_LIB_SUFFIX)

In Makefile.am:

[artifact_name]_LDFLAGS = -lboost_system@BOOST_LIB_SUFFIX@
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!