Seems like I did try that earlier but my problem is something else. Without ClassDb registration, Godot complains:
ERROR: Can't open dynamic library: /home/bla/godot/gd-bla/output/demo/addons/bla/libgdbla-0.0.1.linux.release.x86_64.so. Error: /home/bla/godot/gd-bla/output/demo/addons/bla/libgdbla-0.0.1.linux.release.x86_64.so: undefined symbol: _ZNK5godot7BarClass4_getERKNS_10StringNameERNS_7VariantE.
So undefined symbol for _get()
, I add a ClassDB registration, the full .cpp
file:
#include "bar.h"
#include <godot_cpp/core/class_db.hpp>
using namespace godot;
BarClass::BarClass() {
print_debug("BarClass constructor");
}
void BarClass::_bind_methods() {
ClassDB::bind_method(D_METHOD("_get", "p_name", "r_value"), &BarClass::_get);
}
bool _get(const StringName &p_name, Variant &r_value) {
printf("bla\n");
return false;
}
BarClass::~BarClass() {
print_debug("BarClass destructor");
}
.h
#pragma once
#include <godot_cpp/classes/sprite2d.hpp>
#include <godot_cpp/classes/node.hpp>
#include <godot_cpp/variant/variant.hpp>
#include <godot_cpp/variant/string.hpp>
#include <godot_cpp/variant/string_name.hpp>
#include <godot_cpp/variant/vector2i.hpp>
#include <godot_cpp/classes/node3d.hpp>
#include <godot_cpp/variant/utility_functions.hpp>
#include <godot_cpp/classes/timer.hpp>
#include <godot_cpp/classes/engine.hpp>
#include <godot_cpp/classes/scene_tree.hpp>
namespace godot {
class BarClass : public Node {
GDCLASS(BarClass, Node)
protected:
static void _bind_methods();
public:
BarClass();
~BarClass();
protected:
bool _get(const StringName &p_name, Variant &r_value) const;
};
}
Error:
Compiling shared src/bla.cpp ...
In file included from godot-cpp/include/godot_cpp/core/method_bind.hpp:34,
from godot-cpp/include/godot_cpp/core/class_db.hpp:38,
from godot-cpp/gen/include/godot_cpp/classes/ref_counted.hpp:39,
from godot-cpp/include/godot_cpp/classes/ref.hpp:37,
from godot-cpp/gen/include/godot_cpp/classes/node.hpp:37,
from godot-cpp/gen/include/godot_cpp/classes/canvas_item.hpp:37,
from godot-cpp/gen/include/godot_cpp/classes/node2d.hpp:36,
from godot-cpp/gen/include/godot_cpp/classes/sprite2d.hpp:36,
from src/bla.h:5,
from src/bla.cpp:1:
godot-cpp/include/godot_cpp/core/binder_common.hpp: In instantiation of 'void godot::call_get_argument_type_helper(int, int&, GDExtensionVariantType&) [with Q = Variant&]':
godot-cpp/include/godot_cpp/core/binder_common.hpp:494:53: required from 'GDExtensionVariantType godot::call_get_argument_type(int) [with P = {const StringName&, Variant&}]'
godot-cpp/include/godot_cpp/core/method_bind.hpp:532:39: required from 'GDExtensionVariantType godot::MethodBindTRC<R, P>::gen_argument_type(int) const [with R = bool; P = {const godot::StringName&, godot::Variant&}]'
godot-cpp/include/godot_cpp/core/method_bind.hpp:530:33: required from here
godot-cpp/include/godot_cpp/core/binder_common.hpp:483:63: error: incomplete type 'godot::GetTypeInfo<godot::Variant&, void>' used in nested name specifier
483 | type = GDExtensionVariantType(GetTypeInfo<Q>::VARIANT_TYPE);
| ^~~~~~~~~~~~
godot-cpp/include/godot_cpp/core/binder_common.hpp: In instantiation of 'void godot::call_get_argument_type_info_helper(int, int&, PropertyInfo&) [with Q = Variant&]':
godot-cpp/include/godot_cpp/core/binder_common.hpp:513:58: required from 'void godot::call_get_argument_type_info(int, PropertyInfo&) [with P = {const StringName&, Variant&}]'
godot-cpp/include/godot_cpp/core/method_bind.hpp:541:37: required from 'godot::PropertyInfo godot::MethodBindTRC<R, P>::gen_argument_type_info(int) const [with R = bool; P = {const godot::StringName&, godot::Variant&}]'
godot-cpp/include/godot_cpp/core/method_bind.hpp:538:23: required from here
godot-cpp/include/godot_cpp/core/binder_common.hpp:503:54: error: incomplete type 'godot::GetTypeInfo<godot::Variant&, void>' used in nested name specifier
503 | info = GetTypeInfo<Q>::get_class_info();
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
godot-cpp/include/godot_cpp/core/binder_common.hpp: In instantiation of 'void godot::call_get_argument_metadata_helper(int, int&, GDExtensionClassMethodArgumentMetadata&) [with Q = Variant&]':
godot-cpp/include/godot_cpp/core/binder_common.hpp:533:57: required from 'GDExtensionClassMethodArgumentMetadata godot::call_get_argument_metadata(int) [with P = {const StringName&, Variant&}]'
godot-cpp/include/godot_cpp/core/method_bind.hpp:554:43: required from 'GDExtensionClassMethodArgumentMetadata godot::MethodBindTRC<R, P>::get_argument_metadata(int) const [with R = bool; P = {const godot::StringName&, godot::Variant&}]'
godot-cpp/include/godot_cpp/core/method_bind.hpp:552:49: required from here
godot-cpp/include/godot_cpp/core/binder_common.hpp:521:38: error: incomplete type 'godot::GetTypeInfo<godot::Variant&, void>' used in nested name specifier
521 | md = GetTypeInfo<Q>::METADATA;
| ^~~~~~~~
godot-cpp/include/godot_cpp/core/binder_common.hpp: In instantiation of 'void godot::call_with_variant_args_retc_helper(T*, R (T::*)(P ...) const, const Variant**, Variant&, GDExtensionCallError&, IndexSequence<Is ...>) [with T = _gde_UnexistingClass; R = bool; P = {const StringName&, Variant&}; long unsigned int ...Is = {0, 1}]':
godot-cpp/include/godot_cpp/core/binder_common.hpp:470:36: required from 'void godot::call_with_variant_args_retc_dv(T*, R (T::*)(P ...) const, const void* const*, int, Variant&, GDExtensionCallError&, const std::vector<Variant>&) [with T = _gde_UnexistingClass; R = bool; P = {const StringName&, Variant&}; GDExtensionConstVariantPtr = const void*]'
godot-cpp/include/godot_cpp/core/method_bind.hpp:565:33: required from 'godot::Variant godot::MethodBindTRC<R, P>::call(GDExtensionClassInstancePtr, const void* const*, GDExtensionInt, GDExtensionCallError&) const [with R = bool; P = {const godot::StringName&, godot::Variant&}; GDExtensionClassInstancePtr = void*; GDExtensionConstVariantPtr = const void*; GDExtensionInt = long int]'
godot-cpp/include/godot_cpp/core/method_bind.hpp:560:18: required from here
godot-cpp/include/godot_cpp/core/binder_common.hpp:274:40: error: cannot bind non-const lvalue reference of type 'godot::Variant&' to an rvalue of type 'godot::Variant'
274 | _ret = (p_instance->*p_method)(VariantCaster<P>::cast(*p_args[Is])...);
| ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
godot-cpp/include/godot_cpp/core/binder_common.hpp: In instantiation of 'void godot::call_with_ptr_args_retc_helper(T*, R (T::*)(P ...) const, const void* const*, void*, IndexSequence<Is ...>) [with T = _gde_UnexistingClass; R = bool; P = {const StringName&, Variant&}; long unsigned int ...Is = {0, 1}; GDExtensionConstTypePtr = const void*]':
godot-cpp/include/godot_cpp/core/binder_common.hpp:229:44: required from 'void godot::call_with_ptr_args(T*, R (T::*)(P ...) const, const void* const*, void*) [with T = _gde_UnexistingClass; R = bool; P = {const StringName&, Variant&}; GDExtensionConstTypePtr = const void*]'
godot-cpp/include/godot_cpp/core/method_bind.hpp:573:36: required from 'void godot::MethodBindTRC<R, P>::ptrcall(GDExtensionClassInstancePtr, const void* const*, GDExtensionTypePtr) const [with R = bool; P = {const godot::StringName&, godot::Variant&}; GDExtensionClassInstancePtr = void*; GDExtensionConstTypePtr = const void*; GDExtensionTypePtr = void*]'
godot-cpp/include/godot_cpp/core/method_bind.hpp:569:15: required from here
godot-cpp/include/godot_cpp/core/binder_common.hpp:209:73: error: 'convert' is not a member of 'godot::PtrToArg<godot::Variant&>'
209 | PtrToArg<R>::encode((p_instance->*p_method)(PtrToArg<P>::convert(p_args[Is])...), r_ret);
| ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
scons: *** [src/bla.os] Error 1
scons: building terminated because of errors.
r