Reputation: 9
I am trying to use the asio library on Windows 10, here is a simple test code block:
#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;
}
with Visual Studio 2017. To open a developer command prompt, I use the following command
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools>vsdevcmd
Then, based on the asio doc, I run the command nmake -f Makefile.msc
under the asio src folder. But I am getting an error:
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.
It seems the library requires boost/config.hpp. I really trying to avoid to use the boost. Is there a way I could use the asio standalone on windows 10?
Upvotes: 0
Views: 5448
Reputation: 1
Following command line seems to work. It would be nice addition to boost.asio standalone documentation.
$ nmake STANDALONE=1 -f Makefile.msc
I took me some time to figure out this since I have never used NMAKE even though I have developed a lot of stuff to Windows with MS compiler. It is very not-so-good tool for MAKE process.
Although the make command just executes tests. No lib is generated. Just include headers...
Upvotes: 0
Reputation: 652
To use asio without any boost libraries, you have to define ASIO_STANDALONE
at some point. The best would be in your Visual Studio project, or in your code before any include of asio header.
Upvotes: 1
Reputation: 9
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)
Upvotes: 0