0

我试图了解我的 cmake 设置有什么问题。我下载了http://alexott.net/en/cpp/BoostAsioProxy.html中描述的代码。这是一个使用 boost 的异步 http 代理服务器。

这些是我的 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})

在我输入 cmake 之后。3个源文件编译得很好,但是在链接阶段,我得到了这个:

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

我在 SO 中看到了几篇关于 cmake 和 boost 的此类问题的帖子,但没有一个给出最终答案。为了更清楚地说明问题,让我指出,如果我这样做:

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

源代码编译得很好,这意味着我已经安装了 boost 并且它在正确的位置,问题似乎出在 cmake 上。有什么建议么?

4

1 回答 1

1

The source code archive available on the page ships with its own outdated version of the FindBoost.cmake module. Remove the outdated module file, whose path is asio-proxy-async/cmake/FindBoost.cmake, then re-create your build folder and run cmake again. This will make CMake use the standard FindBoost module which should have no problems finding your existing Boost installation.

于 2012-08-02T19:04:26.253 回答