我正在尝试在Linux VM上编译C ++程序。该程序正在使用boost asio
。 CMakeLists.txt
的外观如下:
project(server_c++)
cmake_minimum_required(VERSION 2.8.4)
set(CMAKE_BINARY_DIR D:\\Sources\\server_c++\\build)
message(STATUS "start running cmake...")
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "/u/refdev64/boost/v1.66.0/include/")
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "/u/refdev64/boost/v1.66.0/")
FIND_PACKAGE(Boost)
if (Boost_FOUND)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
set(Boost_USE_STATIC_LIBS OFF)
ADD_DEFINITIONS( "-DHAS_BOOST" )
endif()
add_executable(Server src/main.cpp src/TcpServer.cpp include/TcpServer.h src/Server.cpp include/Server.h include/ServerParameters.h include/StreamParameters.h include/Message.h src/MessageHandler.cpp include/MessageHandler.h src/Channel_setup.cpp include/Channel_setup.h)
set_property(TARGET Server PROPERTY CXX_STANDARD 11)
find_package(Boost REQUIRED COMPONENTS system)
target_link_libraries(Server boost_system)
不幸的是,启动cmake CMakeLists.txt
时,出现以下错误:
-- start running cmake...
-- Boost version: 1.66.0
-- Boost version: 1.66.0
-- Found the following Boost libraries:
-- system
-- Configuring done
-- Generating done
-- Build files have been written to: /root/Documents
Linking CXX executable Server
/usr/bin/ld: cannot find -lboost_system
collect2: ld returned 1 exit status
gmake[2]: *** [Server] Error 1
gmake[1]: *** [CMakeFiles/Server.dir/all] Error 2
gmake: *** [all] Error 2
由于所有目录都是正确的,并且cmake找到boost
,所以我不会出错。我在CMakeLists.txt
中缺少任何内容吗?
Cmake版本是:2.8.12.2 g ++版本是:5.1.0。
谢谢!
答案 0 :(得分:0)
检查主机中是否安装了boost_system库。
在Ubuntu 16.04发行版中,您可以执行以下操作:
$ dpkg -l | grep libboost
如果未安装,则可以使用:
$ sudo apt-get install libboost-system1.58 libboost-system1.58-dev