I’m trying to understand what’s wrong with my cmake setup. I downloaded the code described in http://alexott.net/en/cpp/BoostAsioProxy.html. It’s an asyncrhonous http proxy server using boost.
These are the contents of my CMakeLists.txt:
cmake_minimum_required(VERSION 2.4)
PROJECT(asio-proxy-async)
# Usage:
# cmake . -DCMAKE_INCLUDE_PATH=~/exp/include -DCMAKE_LIBRARY_PATH=~/exp/lib
#
SET(CMAKE_VERBOSE_MAKEFILE ON)
SET (CMAKE_MODULE_PATH ${cpptests_SOURCE_DIR}/cmake CACHE PATH "local cmake")
ADD_DEFINITIONS(-g -Wall -ansi -Wno-deprecated)
SET(Boost_USE_STATIC_LIBS OFF)
SET(Boost_USE_MULTITHREAD ON)
FIND_PACKAGE(Boost 1.49.0 REQUIRED COMPONENTS filesystem system thread regex)
MESSAGE(STATUS "** Boost Include: ${Boost_INCLUDE_DIR}")
MESSAGE(STATUS "** Boost Libraries: ${Boost_LIBRARIES}")
IF(Boost_FOUND)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
ENDIF(Boost_FOUND)
SET(USED_LIBS ${Boost_SYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_REGEX_LIBRARY})
ADD_EXECUTABLE(asio-proxy-async proxy.cpp proxy-server.cpp proxy-conn.cpp)
TARGET_LINK_LIBRARIES(asio-proxy-async ${USED_LIBS})
After I type cmake . the 3 source files compile just ok, but then in the linking phase, I get this:
Linking CXX executable asio-proxy-async
/usr/bin/cmake -E cmake_link_script CMakeFiles/asio-proxy-async.dir/link.txt --verbose=1
/usr/bin/c++ CMakeFiles/asio-proxy-async.dir/proxy.o CMakeFiles/asio-proxy-async.dir/proxy-server.o CMakeFiles/asio-proxy-async.dir/proxy-conn.o -o asio-proxy-async -rdynamic -lboost_system-mt -lboost_thread-mt -lboost_regex-mt
CMakeFiles/asio-proxy-async.dir/proxy.o: In function `__static_initialization_and_destruction_0':
/usr/local/include/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
CMakeFiles/asio-proxy-async.dir/proxy.o: In function `error_code':
/usr/local/include/boost/system/error_code.hpp:315: undefined reference to `boost::system::system_category()'
CMakeFiles/asio-proxy-async.dir/proxy.o: In function `boost::asio::error::get_system_category()':
/usr/local/include/boost/asio/error.hpp:216: undefined reference to `boost::system::system_category()'
CMakeFiles/asio-proxy-async.dir/proxy.o: In function `thread_exception':
/usr/local/include/boost/thread/exceptions.hpp:49: undefined reference to `boost::system::system_category()'
CMakeFiles/asio-proxy-async.dir/proxy.o: In function `condition_error':
/usr/local/include/boost/thread/exceptions.hpp:82: undefined reference to `boost::system::system_category()'
CMakeFiles/asio-proxy-async.dir/proxy-server.o: In function `__static_initialization_and_destruction_0':
/usr/local/include/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
CMakeFiles/asio-proxy-async.dir/proxy-conn.o: In function `__static_initialization_and_destruction_0':
/usr/local/include/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
collect2: ld returned 1 exit status
make[2]: *** [asio-proxy-async] Error 1
make[2]: Leaving directory `/home/nelsonrp/workspace/boost-test/asio-proxy-async'
make[1]: *** [CMakeFiles/asio-proxy-async.dir/all] Error 2
make[1]: Leaving directory `/home/nelsonrp/workspace/boost-test/asio-proxy-async'
make: *** [all] Error 2
I’ve seen a couple of posts here in SO talking about this kind of problems with cmake and boost, none of them with final answers though. To clarify things a bit more, let me just point out that if I do:
g++ -g -Wall -c proxy.cpp
g++ -g -Wall -c proxy-conn.cpp
g++ -g -Wall -c proxy-server.cpp
g++ proxy.o proxy-server.o proxy-conn.o -o asio-proxy-async -lboost_system -lboost_thread -lboost_regex -lboost_filesystem
The source compiles just fine, which means that I have boost installed and it is in the right place, the problem just seems to be with cmake. Any suggestions?
The source code archive available on the page ships with its own outdated version of the
FindBoost.cmakemodule. Remove the outdated module file, whose path isasio-proxy-async/cmake/FindBoost.cmake, then re-create your build folder and runcmakeagain. This will make CMake use the standardFindBoostmodule which should have no problems finding your existing Boost installation.