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

martinandrovich's profile - activity

2023-07-05 19:17:10 -0500 received badge  Famous Question (source)
2023-07-05 19:17:10 -0500 received badge  Notable Question (source)
2023-01-06 02:49:35 -0500 received badge  Taxonomist
2022-09-05 03:29:04 -0500 received badge  Popular Question (source)
2022-08-30 10:13:29 -0500 edited question ROS2 separate directory for Python nodes

ROS2 python separate nodes directory Is it possible to have a separate directory for Python nodes in ROS2 (foxy)? pytho

2022-08-30 10:13:29 -0500 received badge  Editor (source)
2022-08-29 10:02:15 -0500 asked a question ROS2 separate directory for Python nodes

ROS2 python separate nodes directory Is it possible to have a separate directory for Python nodes in ROS2 (foxy)? pytho

2021-10-05 08:49:16 -0500 received badge  Famous Question (source)
2021-03-20 05:31:55 -0500 received badge  Notable Question (source)
2021-03-01 22:49:27 -0500 received badge  Popular Question (source)
2021-03-01 00:06:40 -0500 asked a question Structure ROS workspaces and packages with Git

Structure ROS workspaces and packages with Git I am setting up a structure for projects and packages. Common packages ar

2020-08-13 06:33:54 -0500 received badge  Famous Question (source)
2020-03-07 04:46:57 -0500 received badge  Enthusiast
2020-03-04 06:09:54 -0500 marked best answer Include methods from another node header (C++)

I have a node with some methods declared in /include/node_1.h and defined in /src/node_1.cpp. Now, I want to include that header into another node /src/node_2.cpp and use the methods there, like:

// node_2.cpp
#include "pkgname/node_1.h"

// ...
some_method_from_node_1();

I can catkin_make with including, but I get a linker error (undefined reference to the method) when trying to compile while calling the method from node_2.

My CMakeLists.txt for the package looks like:

# ...

## declare a catkin package
catkin_package(
    INCLUDE_DIRS include
    CATKIN_DEPENDS message_runtime
)

## include dirs
include_directories(include ${catkin_INCLUDE_DIRS})

## nodes
set(NODES
    node_1
    node_2
)

foreach(node IN LISTS NODES)

    add_executable(${node} src/${node}.cpp)
    target_link_libraries(${node} ${catkin_LIBRARIES})
    add_dependencies(${node} hric_sys_generate_messages_cpp)

endforeach()

How can I make it work and is this approach even idiomatically correct?

EDIT:

So, I have a method called my_test_func(), which I can call from node_1 but get a linker error if I try to invoke it from node_2, although the include works. This is the (simplified) code:

include/node_1.h:

# pragma once

void my_test_func();

src/node_1.cpp:

#include "package/node_1.h"

void my_test_func()
{
    ROS_INFO("API CALL!");
}

int main()
{
    // ...
    my_test_func(); // WORKS
}

src/node_2.cpp:

#include "package/node_1.h"

int main()
{
    // ...
    my_test_func(); // DOESN'T WORK
}
2020-03-04 06:09:54 -0500 received badge  Scholar (source)
2020-03-03 11:17:43 -0500 commented answer Include methods from another node header (C++)

I'm basically trying to call node_1's methods from node_2 that will alter some internal data structure of node_1, e.g. n

2020-03-03 11:17:24 -0500 commented answer Include methods from another node header (C++)

You might be correct that it is not the correct design approach; essentially I am creating a data synchronizer that can

2020-03-03 11:11:51 -0500 commented answer Include methods from another node header (C++)

I'm basically trying to call node_1's methods from node_2 that will alter some internal data structure of node_1, e.g. n

2020-03-03 07:51:46 -0500 commented answer Include methods from another node header (C++)

So, defining the method in the header file works, although I don't understand why it doesn't result in a multiple-defini

2020-03-03 07:44:37 -0500 commented answer Include methods from another node header (C++)

This is pretty much what I've found out as well.. I think that I will turn node_1 into a separate package and compile it

2020-03-03 04:11:01 -0500 received badge  Notable Question (source)
2020-03-03 01:01:33 -0500 received badge  Popular Question (source)
2020-03-02 04:56:55 -0500 edited question Include methods from another node header (C++)

Include methods from another node header (C++) I have a node with some methods declared in /include/node_1.h and defined

2020-03-02 03:06:00 -0500 commented question Include methods from another node header (C++)

So, I added some example code below.. It still doesn't work, even if the method is not inlined.

2020-03-02 03:03:22 -0500 answered a question Include methods from another node header (C++)

So, I have a method called my_test_func(), which I can call from node_1 but get a linker error if I try to invoke it fro

2020-02-28 14:20:07 -0500 commented question Include methods from another node header (C++)

It worked from node_1, yes, and I could include the method in node_2. I didn't upload the full code, because I simplifie

2020-02-28 06:58:09 -0500 asked a question Include methods from another node header (C++)

Include methods from another node header (C++) I have a node with some methods declared in /include/node_1.h and defined