[Boost.Asio] tutorial #1 code does not compile (g++)

Hi All, I am attempting to get acquainted with C++ multithreaded network programming. I have a background in such topics within Java but considering how different C++ is, I am starting from ground zero. I have copied the code from tutorial #1 into my IDE, Timer.1: Using a timer synchronously: https://www.boost.org/doc/libs/1_72_0/doc/html/boost_asio/tutorial/tuttimer1... (follow the link for code). When I tried to compile this (using g++) with the following command: g++ -v -I${BOOST_ROOT} -I. -o main main.cpp (BOOST_ROOT is where I have boost installed), I get the following output: Undefined symbols for architecture x86_64: "boost::chrono::steady_clock::now()", referenced from: boost::asio::detail::chrono_time_traits<boost::chrono::steady_clock, boost::asio::wait_traits<boost::chrono::steady_clock> >::now() in main-c86634.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) Note this is the non-verbose output (I would rather not post the verbose output, as I am trying to keep this post short). I did some digging of my own on Boost's steady_timer documentation and tried to follow that style, as you can find here: https://www.boost.org/doc/libs/1_72_0/doc/html/boost_asio/reference/steady_t... In other words, I replace the two-parameter boost::asio::steady_timer ctor call with a single-parameter ctor call in which I pass an io_context, followed by t.expires_after(std::chrono::seconds(5)); This generated another compiler error, this one to do with 'no viable conversion'. See here: main.cpp:10:21: error: no viable conversion from 'std::chrono::seconds' (aka 'duration<long long>') to 'const boost::asio::basic_waitable_timer<boost::chrono::steady_clock, boost::asio::wait_traits<boost::chrono::steady_clock>, boost::asio::executor>::duration' (aka 'const duration<long long, ratio<(1L), (1000000000L)> >') t.expires_after(std::chrono::seconds(5)); Again, there is more output that I have omitted for brevity. If anyone would like to see the rest of the output, I will gladly supply it. The bottom line is I am not sure what the problem is, or why I am having to debug tutorial code in the first place. This should be relatively simple to "plug & play", should it not? Does this have to do with my compiler? BTW, I am running Mac OS X. Thanks in advance for the help. Sincerely, *AJ*

On Tue, Jan 28, 2020 at 5:41 PM Andrew McFarlane via Boost-users <boost-users@lists.boost.org> wrote:
I have copied the code from tutorial #1 into my IDE, Timer.1: Using a timer synchronously: > https://www.boost.org/doc/libs/1_72_0/doc/html/boost_asio/tutorial/tuttimer1...
You're using the example code from Boost 1.72.0. Are you also using the asio headers from Boost 1.72.0? Or do you have an older version of Boost installed (say, the one that comes with your OS distribution)? Thanks

Your instinct was right, I was using Boost 1.71.0, though replacing that version with 1.72.0 has not fixed the issue. I am getting the same error message as before in both cases. -AJ On Tue, Jan 28, 2020 at 6:04 PM Vinnie Falco <vinnie.falco@gmail.com> wrote:
On Tue, Jan 28, 2020 at 5:41 PM Andrew McFarlane via Boost-users <boost-users@lists.boost.org> wrote:
I have copied the code from tutorial #1 into my IDE, Timer.1: Using a timer synchronously: > https://www.boost.org/doc/libs/1_72_0/doc/html/boost_asio/tutorial/tuttimer1...
You're using the example code from Boost 1.72.0. Are you also using the asio headers from Boost 1.72.0? Or do you have an older version of Boost installed (say, the one that comes with your OS distribution)?
Thanks

Don’t you need to add -lboost_chrono to the gcc command line? Gcc does not do automatic linker comment insertion. On Wed, 29 Jan 2020 at 08:26, Andrew McFarlane via Boost-users < boost-users@lists.boost.org> wrote:
Your instinct was right, I was using Boost 1.71.0, though replacing that version with 1.72.0 has not fixed the issue. I am getting the same error message as before in both cases.
-AJ
On Tue, Jan 28, 2020 at 6:04 PM Vinnie Falco <vinnie.falco@gmail.com> wrote:
On Tue, Jan 28, 2020 at 5:41 PM Andrew McFarlane via Boost-users <boost-users@lists.boost.org> wrote:
I have copied the code from tutorial #1 into my IDE, Timer.1: Using a timer synchronously: > https://www.boost.org/doc/libs/1_72_0/doc/html/boost_asio/tutorial/tuttimer1...
You're using the example code from Boost 1.72.0. Are you also using the asio headers from Boost 1.72.0? Or do you have an older version of Boost installed (say, the one that comes with your OS distribution)?
Thanks
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org https://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Richard Hodges hodges.r@gmail.com office: +442032898513 home: +376841522 mobile: +376380212

Le 29/01/2020 à 02:14, Andrew McFarlane via Boost-users a écrit :
Undefined symbols for architecture x86_64:
"boost::chrono::steady_clock::now()", referenced from:
boost::asio::detail::chrono_time_traits<boost::chrono::steady_clock, boost::asio::wait_traits<boost::chrono::steady_clock> >::now() in main-c86634.o
I think you'll need to link against boost_chrono then. -- David
participants (4)
-
Andrew McFarlane
-
David Demelier
-
Richard Hodges
-
Vinnie Falco