Quantcast
Channel: ROS Answers: Open Source Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 43

how to run libmodbus

$
0
0
I added include_directories(include /usr/include/libmodbus) to the CMakeList.txt of my package, and my test node is #include #include 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)

Viewing all articles
Browse latest Browse all 43

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>