Home | Tutorials | Wiki | Issues
Ask Your Question

Revision history [back]

Cannot Compile Custom Plugins


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/plugin_test.cc:10:3: 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/plugin_test.cc:2:
/home/joey/Gazebo Stuff/bart_world_plugin/plugin_test.cc: 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/plugin_test.cc:37:3: note: in expansion of macro ‘GZ_REGISTER_MODEL_PLUGIN’
CMakeFiles/plugin_test.dir/build.make:62: recipe for target 'CMakeFiles/plugin_test.dir/plugin_test.cc.o' failed
make[2]: *** [CMakeFiles/plugin_test.dir/plugin_test.cc.o] 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 model_push.cc; this is my "custom" plugin, plugin_test.cc 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 plugin_test.cc)
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.