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

Christian Hidalgo's profile - activity

2016-06-22 07:12:46 -0500 received badge  Famous Question (source)
2016-04-11 23:00:09 -0500 received badge  Supporter (source)
2016-04-11 23:00:06 -0500 received badge  Scholar (source)
2016-04-08 17:32:12 -0500 received badge  Notable Question (source)
2016-04-07 08:41:09 -0500 received badge  Popular Question (source)
2016-04-06 17:37:01 -0500 asked a question how to run libmodbus

I added

include_directories(include /usr/include/libmodbus)

to the CMakeList.txt of my package, and my test node is

#include <ros/ros.h>
#include <libmodbus/src/modbus.h>


int main(int argc, char** argv) {
  modbus_t *Scara;
  Scara = modbus_new_tcp("192.168.1.219", 502);
        if (modbus_connect(Scara) == -1) {
            ROS_ERROR("Conexion fallida");
            modbus_free(Scara);
        }else{
            ROS_INFO("Conexion exitosa");
        }                      

  return 0;
}

but when i run catkin_make i get the following errors

In function `main':
scaraListen.cpp:(.text+0x1b): undefined reference to `modbus_new_tcp'
scaraListen.cpp:(.text+0x2b): undefined reference to `modbus_connect'
scaraListen.cpp:(.text+0x135): undefined reference to `modbus_free' 
collect2: error: ld returned 1 exit status

It seems that it's not linking to the library, but when i add

target_link_libraries(main /usr/include/libmodbus.so)

to the CMakeList.txt and try to compile i get:

(target_link_libraries):
   Cannot specify link libraries for target "main" which is not built by this project.

Where i'm messing up?

EDIT: my complete CMakeList.txt looks like this

cmake_minimum_required(VERSION 2.8.3)
project(pointCloud)


find_package(catkin REQUIRED COMPONENTS
  pcl_conversions
  pcl_msgs
  pcl_ros
  roscpp
  rospy
  std_msgs
  sensor_msgs
  tf
  laser_geometry
)

include_directories(
  ${catkin_INCLUDE_DIRS}
)


include_directories(include ${catkin_INCLUDE_DIRS})
include_directories(include /usr/include/libmodbus)

add_executable(converter src/converter.cpp)
target_link_libraries(converter ${catkin_LIBRARIES})
add_dependencies(converter pointCloud_conv)

add_executable(tfTest src/tftest.cpp)
target_link_libraries(tfTest ${catkin_LIBRARIES})
add_dependencies(tfTest pointCloud_conv)

add_executable(scaraListen src/scaraListen.cpp)
target_link_libraries(scaraListen ${catkin_LIBRARIES})
add_dependencies(scaraListen pointCloud_conv)