GDExtension compile error

Godot Version

4.2.1

Question

I am having trouble compiling my GDExtension… It worked fine without the bind_method call, so I assume it is something wrong there…
Here is the Error I am getting:

user@rpi5:~/Documents/Coding/GDserial $ scons platform=linux
scons: Reading SConscript files ...
Auto-detected 4 CPU cores available for build parallelism. Using 4 cores by default. You can override it with the -j argument.
Building for architecture arm64 on platform linux
scons: done reading SConscript files.
scons: Building targets ...
scons: `godot-cpp/bin/libgodot-cpp.linux.template_debug.arm64.a' is up to date.
g++ -o src/serialNode.os -c -fno-gnu-unique -fno-exceptions -std=c++17 -fPIC -Wwrite-strings -march=armv8-a -O2 -fvisibility=hidden -fPIC -DHOT_RELOAD_ENABLED -DLINUX_ENABLED -DUNIX_ENABLED -DDEBUG_ENABLED -DDEBUG_METHODS_ENABLED -DNDEBUG -Igodot-cpp/gdextension -Igodot-cpp/include -Igodot-cpp/gen/include -Isrc src/serialNode.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:41,
                 from src/serialNode.h:4,
                 from src/serialNode.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 = const char*]':
godot-cpp/include/godot_cpp/core/binder_common.hpp:494:53:   required from 'GDExtensionVariantType godot::call_get_argument_type(int) [with P = {const char*}]'
godot-cpp/include/godot_cpp/core/method_bind.hpp:448:39:   required from 'GDExtensionVariantType godot::MethodBindTR<R, P>::gen_argument_type(int) const [with R = int; P = {const char*}]'
godot-cpp/include/godot_cpp/core/method_bind.hpp:446:33:   required from here
godot-cpp/include/godot_cpp/core/binder_common.hpp:483:63: error: incomplete type 'godot::GetTypeInfo<const char*, 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 = const char*]':
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 char*}]'
godot-cpp/include/godot_cpp/core/method_bind.hpp:457:37:   required from 'godot::PropertyInfo godot::MethodBindTR<R, P>::gen_argument_type_info(int) const [with R = int; P = {const char*}]'
godot-cpp/include/godot_cpp/core/method_bind.hpp:454:23:   required from here
godot-cpp/include/godot_cpp/core/binder_common.hpp:503:54: error: incomplete type 'godot::GetTypeInfo<const char*, 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 = const char*]':
godot-cpp/include/godot_cpp/core/binder_common.hpp:533:57:   required from 'GDExtensionClassMethodArgumentMetadata godot::call_get_argument_metadata(int) [with P = {const char*}]'
godot-cpp/include/godot_cpp/core/method_bind.hpp:470:43:   required from 'GDExtensionClassMethodArgumentMetadata godot::MethodBindTR<R, P>::get_argument_metadata(int) const [with R = int; P = {const char*}]'
godot-cpp/include/godot_cpp/core/method_bind.hpp:468:49:   required from here
godot-cpp/include/godot_cpp/core/binder_common.hpp:521:38: error: incomplete type 'godot::GetTypeInfo<const char*, void>' used in nested name specifier
  521 |                 md = GetTypeInfo<Q>::METADATA;
      |                                      ^~~~~~~~
godot-cpp/include/godot_cpp/core/binder_common.hpp: In instantiation of 'static T godot::VariantCasterAndValidate<T>::cast(const godot::Variant**, uint32_t, GDExtensionCallError&) [with T = const char*; uint32_t = unsigned int]':
godot-cpp/include/godot_cpp/core/binder_common.hpp:261:67:   required from 'void godot::call_with_variant_args_ret_helper(T*, R (T::*)(P ...), const Variant**, Variant&, GDExtensionCallError&, IndexSequence<Is ...>) [with T = _gde_UnexistingClass; R = int; P = {const char*}; long unsigned int ...Is = {0}]'
godot-cpp/include/godot_cpp/core/binder_common.hpp:435:35:   required from 'void godot::call_with_variant_args_ret_dv(T*, R (T::*)(P ...), const void* const*, int, Variant&, GDExtensionCallError&, const std::vector<Variant>&) [with T = _gde_UnexistingClass; R = int; P = {const char*}; GDExtensionConstVariantPtr = const void*]'
godot-cpp/include/godot_cpp/core/method_bind.hpp:481:32:   required from 'godot::Variant godot::MethodBindTR<R, P>::call(GDExtensionClassInstancePtr, const void* const*, GDExtensionInt, GDExtensionCallError&) const [with R = int; P = {const char*}; GDExtensionClassInstancePtr = void*; GDExtensionConstVariantPtr = const void*; GDExtensionInt = long int]'
godot-cpp/include/godot_cpp/core/method_bind.hpp:476:18:   required from here
godot-cpp/include/godot_cpp/core/binder_common.hpp:150:89: error: incomplete type 'godot::GetTypeInfo<const char*, void>' used in nested name specifier
  150 |                 GDExtensionVariantType argtype = GDExtensionVariantType(GetTypeInfo<T>::VARIANT_TYPE);
      |                                                                                         ^~~~~~~~~~~~
scons: *** [src/serialNode.os] Error 1
scons: building terminated because of errors.

Here are the relevant files:
serialNode.h

#ifndef SERIAL_NODE_H
#define SERIAL_NODE_H

#include "godot_cpp/classes/node.hpp"

#include <termios.h>

namespace godot
{
  class GDserial : public Node
  {
    GDCLASS(GDserial, Node)

    private:
      int usbfd;
      int state;
      struct termios portData;

    protected:
      static void _bind_methods();

    public:
      int setPort(const char* path);

      GDserial();
      ~GDserial();

      void _process(double delta) override;
  };
}

#endif

serialNode.cpp

#include "serialNode.h"
#include "godot_cpp/core/class_db.hpp"

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>

using namespace godot;

void GDserial::_bind_methods()
{
  ClassDB::bind_method(D_METHOD("setPort", "path"), &GDserial::setPort);
}

GDserial::GDserial()
{
  usbfd = 0;
  state = 0;
}

GDserial::~GDserial()
{

}

void GDserial::_process(double delta)
{
  
}

int GDserial::setPort(const char* path)
{
  . . .
}

register_types.cpp

#include "register_types.h"

#include "serialNode.h"

#include <gdextension_interface.h>
#include <godot_cpp/core/defs.hpp>
#include <godot_cpp/godot.hpp>

using namespace godot;

void initialize_module(ModuleInitializationLevel p_level) {
	if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
		return;
	}

	ClassDB::register_class<GDserial>();
}

void uninitialize_module(ModuleInitializationLevel p_level) {
	if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
		return;
	}
}

extern "C" {
// Initialization.
GDExtensionBool GDE_EXPORT example_library_init(GDExtensionInterfaceGetProcAddress p_get_proc_address, const GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) {
	godot::GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library, r_initialization);

	init_obj.register_initializer(initialize_module);
	init_obj.register_terminator(uninitialize_module);
	init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);

	return init_obj.init();
}
}

register_types.h

#ifndef GDSERIAL_REGISTER_TYPES_H
#define GDSERIAL_REGISTER_TYPES_H

#include "godot_cpp/core/class_db.hpp"

using namespace godot;

void initialize_module(ModuleInitializationLevel p_level);
void uninitialize_module(ModuleInitializationLevel p_level);

#endif

Thanks for help in advance!

From the error I don’t think it likes the char* you may need to use godt string or node path variants

1 Like

@pennyloafers
Thanks for your Help, how would I use any of those?

**Edit: ** I figured it out myself, thanks again for the help

Looking around the Godot source, they do use char* altho never as gdclass interface function parameters. Sorry I wasn’t clear about that. Glad it worked

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.