ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

I can't use boost/asio library properly. [closed]

asked 2021-01-19 08:07:12 -0500

serhat gravatar image

updated 2021-01-19 08:09:03 -0500

Hello, I am working on a program where i need to get some datas from a PLC by using TCP/IP protocol. I viewed that related thread on this website. (https://answers.ros.org/question/1060...)

After some basic searchs, I decided to create an "adapter" process. And for that regard, I tried to use Boost/Asio library. For this, I visited this website (https://www.boost.org/doc/libs/1_75_0...)

But then strange things happen, after including the " boost/asio.hpp " to my program. I was not even able to create an boost::asio::io_context object. And I don't know why. I leave my basic program below. The problem might be related to my program's CMakeList.txt. How can i solve this problem and using Boost/Asio library properly for TCP/IP communication.

#include "ros/ros.h"
#include "std_msgs/String.h"
#include <sstream>
#include <iostream>

#include <boost/asio.hpp>

using namespace std ; 

int main(int argc, char **argv)
{
    boost::asio::io_context io ;  //THE PROBLEM HERE --> namespace "boost::asio" has no member "io_context"C/C++(135)

    // boost::asio::ip::tcp::socket socket(io);

    // boost::asio::steady_timer t(io, boost::asio::chrono::seconds(5));

    while (ros::ok())
    {
      //some code
    }
    return 0;
}

UBUNTU 16.04 - Kinetic - Ros1. I use Visual Studio as IDE.

Thank You!

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by serhat
close date 2021-04-27 08:32:54.546890

2 Answers

Sort by ยป oldest newest most voted
1

answered 2021-02-01 00:22:37 -0500

serhat gravatar image

updated 2021-02-01 00:23:23 -0500

Hi all, I found the solution of the problem. Please see the following link to see my quick solution. https://answers.ros.org/question/3704...

edit flag offensive delete link more
0

answered 2021-01-19 08:34:22 -0500

Vic gravatar image

This guy have a similar issue : https://stackoverflow.com/questions/6...

Else, I personnally use some python code embedded in C++ to deal with PLC. Mine is pylogix, check if something like this exist for your use case

edit flag offensive delete link more

Comments

1

Thank you Vic! After some search, I realized that I'm using one of the old version of Boost library. I check the information via this in my program:

#include <boost/asio.hpp>
std::cout << BOOST_LIB_VERSION << std::endl ;

As output, I gave 1_58 which is a very old version of the Boost Library. In this version(1_58), there is no "io_context" object at all. And that is why I faced this 'problem' written above. In fact, I have no clue how this version of Boost library is set by default. I'll try to upgrade the Boost library to latest version.(Currently, it is Version 1.75.0)

I don't know how to upgrade though :) but I will try. By the way, thank you for advising another third party libraries for my issue.

serhat gravatar image serhat  ( 2021-01-20 00:17:32 -0500 )edit

In fact, I have no clue how this version of Boost library is set by default.

Because you seem to be running:

UBUNTU 16.04 - Kinetic - Ros1

as you write yourself in the OP.

Default Boost version on Ubuntu Xenial (16.04) is 1.58 (see here).

I'll try to upgrade the Boost library to latest version.(Currently, it is Version 1.75.0)

you don't want to do that.

Mixing Boost versions is a quick route to all sorts of SEGFAULTs.

It can be done, but you'd have to build all of ROS from source, including its dependencies if/when they also link to Boost.

There are multiple Q&As on this topic here on this site.

ROS Kinetic will be EOL in about 3 months: do you really need to use it? If not: update to a more recent version of Ubuntu and Boost itself ...(more)

gvdhoorn gravatar image gvdhoorn  ( 2021-01-20 01:54:15 -0500 )edit

Hi gvdhoorn, I upgraded my boost library by following these step:(I saw your command new unfortunately!)

I downloaded latest Boost library from this page( https://www.boost.org/users/history/v... ) I changed my current boost directory(usr/include/boost) to the latest version that I just downloaded. (I deleted old version first and then copy the new one)

Therefore, I use the version 1_75_0 of Boost library now. And It works fine so far!

you don't want to do that.
Mixing Boost versions is a quick route to all sorts of SEGFAULTs.

I don't know what SEGFAULT is unfortunately.You think that I can keep working with my new set up? Or not?What would you suggest me to do for using latest version of the Boost library instead of "deleting the old one in src/include and copy new one"?

I appreciate your answers!

serhat gravatar image serhat  ( 2021-01-20 04:44:17 -0500 )edit

I changed my current boost directory(usr/include/boost) to the latest version that I just downloaded. (I deleted old version first and then copy the new one)

don't ever do this on OS with package managers. Your package manager is unaware of this change and will happily overwrite (and thus revert) everything (probably partially too) the next time Boost gets an update distributed by Canonical (even old versions get security updates).

You also imply you've only updated the headers, and not the libraries. That's also not a good idea.

(but updating a system dependency like this is not a good idea in any case, so please don't go and overwrite the libraries now as well)

I don't know what SEGFAULT is unfortunately

wikipedia/Segmentation fault.

Summary: crashes of your programs with the SEGFAULT signal (-11 typically). Hard to debug, impossible to prevent / catch.

Mixing ...(more)

gvdhoorn gravatar image gvdhoorn  ( 2021-01-20 05:02:09 -0500 )edit

.. is a known way of introducing such instability.

You think that I can keep working with my new set up?

Personally I would never do what you just did. If you need a newer version of a dependency, see whether you can install it using your package manager. If not: upgrade the OS.

Boost is such a 'central dependency' (ie: used by many programs) that it's not a good idea to (partially) replace it with a different version.

Whether it is something you can keep using is something only you can answer.

gvdhoorn gravatar image gvdhoorn  ( 2021-01-20 05:04:05 -0500 )edit

Hi gvdhoorn, could you take a look at your university mail. Thanks!

serhat gravatar image serhat  ( 2021-01-21 00:19:29 -0500 )edit

Please do not send me private emails about ROS Answers topics.

gvdhoorn gravatar image gvdhoorn  ( 2021-01-21 02:03:20 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2021-01-19 08:07:12 -0500

Seen: 1,424 times

Last updated: Feb 01 '21