1
$\begingroup$

I'm trying to make custom gz sim plugin by following the examples folder. After build the example I'm getting error

gz sim -s -v 4 sample_system.sdf: symbol lookup error: /home/JF/Projects/system_plugin/build/libSampleSystem.so: undefined symbol: GzPluginHook

Referring to this example https://github.com/gazebosim/gz-sim/tree/gz-sim7/examples/plugin/system_plugin, any ideas? Using Gazebo Garden

SampleSystem.cc


#include "SampleSystem.hh"

#include <gz/plugin/RegisterMore.hh>
#include <gz/sim/components/Link.hh>

GZ_ADD_PLUGIN(
    SampleSystem,
    gz::sim::System,
    SampleSystem::ISystemPreUpdate,
    SampleSystem::ISystemUpdate,
    SampleSystem::ISystemPostUpdate,
    SampleSystem::ISystemReset)


SampleSystem::SampleSystem()
{
}

SampleSystem::~SampleSystem()
{
}

void SampleSystem::PreUpdate(const gz::sim::UpdateInfo &_info,
    gz::sim::EntityComponentManager &_ecm)
{
  gzmsg << "SampleSystem::PreUpdate" << std::endl;
}

void SampleSystem::Update(const gz::sim::UpdateInfo &_info,
    gz::sim::EntityComponentManager &_ecm)
{
  gzmsg << "SampleSystem::Update" << std::endl;
}

void SampleSystem::PostUpdate(const gz::sim::UpdateInfo &_info,
    const gz::sim::EntityComponentManager &_ecm)
{
  gzmsg << "SampleSystem::PostUpdate" << std::endl;
}

void SampleSystem::Reset(const gz::sim::UpdateInfo &_info,
     gz::sim::EntityComponentManager &_ecm)
{
  gzmsg << "SampleSystem::Reset" << std::endl;
}

SampleSystem.hh

/*
 * Copyright (C) 2018 Open Source Robotics Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
*/
#ifndef SAMPLESYSTEM_HH_
#define SAMPLESYSTEM_HH_

//! [header]
#include <gz/sim/System.hh>


class SampleSystem:
// This class is a system.
public gz::sim::System,
// This class also implements the ISystemPreUpdate, ISystemUpdate,
// and ISystemPostUpdate interfaces.
public gz::sim::ISystemPreUpdate,
public gz::sim::ISystemUpdate,
public gz::sim::ISystemPostUpdate,
public gz::sim::ISystemReset
{
    public: SampleSystem();

    public: ~SampleSystem() override;

    public: void PreUpdate(const gz::sim::UpdateInfo &_info,
                gz::sim::EntityComponentManager &_ecm) override;

    public: void Update(const gz::sim::UpdateInfo &_info,
                gz::sim::EntityComponentManager &_ecm) override;

    public: void PostUpdate(const gz::sim::UpdateInfo &_info,
                const gz::sim::EntityComponentManager &_ecm) override;

    public: void Reset(const gz::sim::UpdateInfo &_info,
                 gz::sim::EntityComponentManager &_ecm) override;
};

#endif

CMakeLists.txt

cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)

find_package(gz-cmake3 REQUIRED)

project(SampleSystem)

find_package(gz-plugin2 REQUIRED COMPONENTS register)
set(GZ_PLUGIN_VER ${gz-plugin2_VERSION_MAJOR})

find_package(gz-sim7 REQUIRED)
set(GZ_SIM_VER ${gz-sim7_VERSION_MAJOR})

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


add_library(SampleSystem SHARED SampleSystem.cc)

target_link_libraries(SampleSystem 
    gz-plugin${GZ_PLUGIN_VER}::gz-plugin${GZ_PLUGIN_VER} 
    gz-sim${GZ_SIM_VER}::gz-sim${GZ_SIM_VER})
$\endgroup$
2
  • 1
    $\begingroup$ Can you try #include <gz/plugin/Register.hh> instead of #include <gz/plugin/RegisterMore.hh>. The latter is if you are registering multiple classes in multiple translation units, but it assumes the former is included somwehre. $\endgroup$
    – azeey
    Commented Jan 9 at 4:13
  • $\begingroup$ @azeey Omg, that fixed it! Can you add it as answer, I'll accept it. Thank you!! $\endgroup$
    – Jay Parikh
    Commented Jan 9 at 15:53

2 Answers 2

1
$\begingroup$

You should use #include <gz/plugin/Register.hh> instead of #include <gz/plugin/RegisterMore.hh>. The latter is if you are registering multiple classes in multiple translation units, but it assumes the former is included somewhere.

$\endgroup$
0
$\begingroup$

In order for a system plugin to be registered and recognized by the simulator, you must add a macro to one of the translation units in your shared library to register it.

In the example, the code looks like this:

GZ_ADD_PLUGIN(
    sample_system::SampleSystem,
    gz::sim::System,
    sample_system::SampleSystem::ISystemPostUpdate)

Where the arguments are the fully qualified system name (including all namespaces), the base system class gz::sim::System, and then each of the interfaces that your system implements. In the example, this is just "PostUpdate".

As you were modifying the example, you may have accidentally removed this macro. Without it, the shared library will not be recognized as a valid plugin.

$\endgroup$
2
  • $\begingroup$ I cross checked, I do have that. (note: I removed sample_system namepsace) GZ_ADD_PLUGIN( SampleSystem, gz::sim::System, SampleSystem::ISystemPreUpdate, SampleSystem::ISystemUpdate, SampleSystem::ISystemPostUpdate, SampleSystem::ISystemReset) $\endgroup$
    – Jay Parikh
    Commented Jan 9 at 3:06
  • $\begingroup$ Added code for your reference $\endgroup$
    – Jay Parikh
    Commented Jan 9 at 3:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.