moongoal
moongoal

Reputation: 2956

Making autoconf search for C++ libraries

I'm writing my first configure.ac and need to search for a C++ library.

I tried the following line, but when run the configure script, it finds nothing.

AC_SEARCH_LIBS([xmlpp::Document::get_root_node], [xml++-2.6])

Probably something is wrong with it. So, how can I make autoconf look for C++ libraries? I don't want to supply a global method (and don't think libxml++ has one either).

Upvotes: 3

Views: 2327

Answers (3)

Kemin Zhou
Kemin Zhou

Reputation: 6891

This link is about finding a C-style signature function to the library so that it can be tested by autoconf or write your own test:

https://nerdland.net/2009/07/detecting-c-libraries-with-autotools/

Maybe worth to try, but I am getting an error with the AC_LANG_PROGRAM macro. The problem is put -llibname before the foo.cpp file. My compiler cares about the order of the -l and cpp file. The linker will not be able to find the function in the library.

Upvotes: 0

Hasturkun
Hasturkun

Reputation: 36402

You might want to try AX_CXX_CHECK_LIB from the Autoconf macro archive. you should probably make sure that you either use AC_LANG([C++]) or surround the call with AC_LANG_PUSH([C++]) and AC_LANG_POP([C++]).

Upvotes: 6

matiu
matiu

Reputation: 7725

Hope this helps. My suggestion would be to use CMake instead of Autoconf.

This CMakeLists.txt file should get you started:

cmake_minimum_required(VERSION 2.8)

# http://www.cmake.org/cmake/help/cmake-2-8-docs.html#module:FindLibXml2
find_package(libxml2 2.6 REQUIRED) # http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:find_package

include_directories(${LIBXML2_INCLUDE_DIR}) # http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:include_directories

add_executable(myApp main.cpp other.cpp) # http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_executable
target_link_libraries(myApp ${LIBXML2_LIBRARIES}) # http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:target_link_libraries

To use the file, after adjusting for your project of course. Put it in your Source dir as CMakeLists.txt, then:

mkdir build
cd build
cmake .. # This is like autoconf and generates the make files
make

If it sounds intriguing check out the giant youtube vid on all the benefits: http://www.youtube.com/watch?v=8Ut9o4OdSC0

It's good to use CMake, CTest, CDash, and CPack together in a project.

Upvotes: -3

Related Questions