我正在尝试在Windows 10上使用asio库,这是一个简单的测试代码块:
#include <iostream>
#include <asio.hpp>
using std::cout;
int main()
{
std::cout << "hello asio\n";
asio::io_context ioc;
asio::steady_timer tmer(ioc, asio::chrono::seconds(1));
tmer.wait();
cout << "hi asio\n";
ioc.run();
return 0;
}
在Visual Studio 2017中。要打开开发人员命令提示符,我使用以下命令
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools>vsdevcmd
然后,基于asio doc,我在asio src文件夹下运行命令nmake -f Makefile.msc
。但是我遇到一个错误:
Microsoft (R) Program Maintenance Utility Version 14.16.27025.1
Copyright (C) Microsoft Corporation. All rights reserved.
cl -Fetests\latency\tcp_client.exe -Fotests\latency\tcp_client.obj -nologo -EHac -GR -I. -I../include -O2 -MD -I../../boost_1_34_1 -D_WIN32_WINNT=0x0501 -DBOOST_ALL_NO_LIB -DBOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING tests\latency\tcp_client.cpp -link -opt:ref
tcp_client.cpp
../include\asio/detail/config.hpp(26): fatal error C1083: Cannot open include file: 'boost/config.hpp': No such file or directory
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\cl.EXE"' : return code '0x2'
Stop.
似乎该库需要boost / config.hpp。我真的试图避免使用助推器。有什么方法可以在Windows 10上独立使用asio?
答案 0 :(得分:1)
要使用不带任何Boost库的Asio,必须在某个时候定义ASIO_STANDALONE
。最好是在您的Visual Studio项目中,或在包含asio标头之前的代码中。
答案 1 :(得分:0)
I tried to use vcpkg, but it turns out I only need to download the library and create a cmake file to do the job.
cmake_minimum_required(VERSION 3.12)
project(asio)
add_definitions(-DASIO_STANDALONE -D_WIN32_WINNT=0x0501)
# -DBOOST_DATE_TIME_NO_LIB -DBOOST_REGEX_NO_LIB)
# include_directories(${VCPKG_DIR}//asio_x86-windows//include)
include_directories(./../libs/asio-1.12.2/include)
add_executable(asio s5.cpp)