Gazebo | Ignition | Community
Ask Your Question

Cannot Compile Custom Plugins

asked 2019-05-17 10:57:27 -0600

JosephT gravatar image


I went through the Write-a-Plugin tutorials and decided to try and write one to get the process down. To start, I just tried to replace some words in the tutorial code to see if I was understanding it correctly. It turns out I'm not, and I'm very confused as to what's going wrong as I get this when I run the 'make' command in the build directory. The tutorials run without error, but when I change the class name, the compiler no longer recognizes it:

/home/joey/Gazebo Stuff/bart_world_plugin/ error: expected class-name before ‘{’ token
In file included from /usr/include/gazebo-9/gazebo/common/common.hh:36:0,
                 from /usr/include/gazebo-9/gazebo/gazebo_core.hh:19,
                 from /usr/include/gazebo-9/gazebo/gazebo.hh:20,
                 from /home/joey/Gazebo Stuff/bart_world_plugin/
/home/joey/Gazebo Stuff/bart_world_plugin/ In function ‘gazebo::ModelPlugin* gazebo::RegisterPlugin()’:
/usr/include/gazebo-9/gazebo/common/Plugin.hh:432:26: error: cannot convert ‘gazebo::PluginTest*’ to ‘gazebo::ModelPlugin*’ in return
     return new classname();\
/home/joey/Gazebo Stuff/bart_world_plugin/ note: in expansion of macro ‘GZ_REGISTER_MODEL_PLUGIN’
CMakeFiles/plugin_test.dir/build.make:62: recipe for target 'CMakeFiles/plugin_test.dir/' failed
make[2]: *** [CMakeFiles/plugin_test.dir/] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/plugin_test.dir/all' failed
make[1]: *** [CMakeFiles/plugin_test.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

The file in question is based off; this is my "custom" plugin, where I only changed class name and the public name in what I believed to be the correct spots:

#include <functional>
#include <gazebo/gazebo.hh>
#include <gazebo/physics/physics.hh>
#include <gazebo/common/common.hh>
#include <ignition/math/Vector3.hh>

namespace gazebo
  class PluginTest : public PluginTestPlugin
    public: void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/)
      // Store the pointer to the model
      this->model = _parent;

      // Listen to the update event. This event is broadcast every
      // simulation iteration.
      this->updateConnection = event::Events::ConnectWorldUpdateBegin(
          std::bind(&PluginTest::OnUpdate, this));

    // Called by the world update start event
    public: void OnUpdate()
      // Apply a small linear velocity to the model.
      this->model->SetLinearVel(ignition::math::Vector3d(0, 500, 0));

    // Pointer to the model
    private: physics::ModelPtr model;

    // Pointer to the update event connection
    private: event::ConnectionPtr updateConnection;

  // Register this plugin with the simulator

Here's CMakeLists.txt:

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

find_package(gazebo REQUIRED)

add_library(plugin_test SHARED
target_link_libraries(plugin_test ${GAZEBO_LIBRARIES})

The only other thing I could find on the topic of a custom plugin not compiling was solved by adding another include, but that didn't seem to have an effect on my plugin.

edit retag flag offensive close merge delete


Found the problem: apparently the public name has to be ModelPlugin (in this case, at least). I'm assuming that the first word changes depending on plugin type?

JosephT gravatar imageJosephT ( 2019-05-18 08:55:31 -0600 )edit

1 Answer

Sort by » oldest newest most voted

answered 2019-05-19 12:44:45 -0600

chapulina gravatar image

Found the problem: apparently the public name has to be ModelPlugin (in this case, at least). I'm assuming that the first word changes depending on plugin type?

Correct, the name coming after public there is the name of the class which your plugin is inheriting from. In your case, since you're using GZ_REGISTER_MODEL_PLUGIN, you need to inherit from gazebo::ModelPlugin. There are also other types available, like WorldPlugin and VisualPlugin.

See this tutorial for more info.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-05-17 10:55:10 -0600

Seen: 442 times

Last updated: May 19 '19