Compiling the plugin

We should make sure that Gazebo has been properly installed. To compile the preceding plugin, we will create ~/gazebo_plugin_tutorial/CMakeLists.txt and add the rule for compilation:

cmake_minimum_required(VERSION 2.8 FATAL_ERROR) 
find_package(gazebo REQUIRED) 
include_directories(${GAZEBO_INCLUDE_DIRS}) 
link_directories(${GAZEBO_LIBRARY_DIRS}) 
list(APPEND CMAKE_CXX_FLAGS "${GAZEBO_CXX_FLAGS}") 
 
add_library(hello_world SHARED hello_world.cc) 
target_link_libraries(hello_world ${GAZEBO_LIBRARIES}) 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GAZEBO_CXX_FLAGS}") 

Next, we will create the build directory and compile the code:

$ mkdir ~/gazebo_plugin_tutorial/build
$ cd ~/gazebo_plugin_tutorial/build
$ cmake ..
$ make  

The successful compilation will generate a shared library, ~/gazebo_plugin_tutorial/build/libhello_world.so, that can be inserted in a Gazebo simulation. Lastly, we have to add a library path to the GAZEBO_PLUGIN_PATH:

$ export GAZEBO_PLUGIN_PATH=${GAZEBO_PLUGIN_PATH}:~/gazebo_plugin_tutorial/build  
This only adds the path for the current shell. If we want to use our plugin for every new terminal we open, we have to append the preceding line to the ~/.bashrc file.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.67.26