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})
#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$