Skip to content

Virtual function with Node* argument - Undefined Symbol Under Linux #1480

Closed

Description

@Kehom

Godot version

4.3 beta 1

godot-cpp version

master

System information

Windows 10 and Linux Mint

Issue description

I'm not sure if I'm setting up something incorrectly or not. Nevertheless, if I declare a virtual function that contains an argument that is a pointer to Node or any derived class, then Godot fails to load the extension under Linux, telling that there is undefined symbol GetTypeInfo??WhateverArgumentType. Yet it does work fine under Windows (using MS compiler - was unable to compile using MingW).

Just to make sure the error was indeed related to the argument type within the GDVIRTUAL macro, I changed the argument type to Variant and errors went away.

Steps to reproduce

  • In a custom class add:
GDVIRTUAL1(_some_virtual_function, godot::Control*);
  • Attempt to load the resulting extension under Linux

It should result in Undefined symbol ???godot??GetTypeInfo???Control?METADATAE
The "?" above are artifacts of the compiler.

Minimal reproduction project

Activity

  1. AThousandShips commented on Jun 4, 2024

    @AThousandShips
    Member

    Did you also bind it in the code? You can't just add GDVIRTUAL you also need to add GDVIRTUAL_BIND(_some_virtual_function, "arg"); to _bind_methods

  2. Kehom commented on Jun 4, 2024

    @Kehom
    ContributorAuthor

    Yes, I did add the GDVIRTUAL_BIND(). Sorry I forgot to mention that. But then, without it I don't think the code would have worked under Windows or with Variant instead of anything derived from Node*.

    Again, I might have messed up something in the setup. Yet, because the code does work when not using Node* (or derived) as argument type, I suspect there is something else at play.

  3. added
    topic:gdextension
    on Jun 4, 2024
  4. AThousandShips commented on Jun 5, 2024

    @AThousandShips
    Member

    Does it work if you do ::Godot::Control?

  5. Kehom commented on Jun 5, 2024

    @Kehom
    ContributorAuthor

    Unfortunately no. It's the exact same behavior. Compilation goes OK, but when attempting to open the project comes the undefined symbol error message. It does work very fine with either GDVIRTUAL1(_some_virtual, godot::Variant) or GDVIRTUAL1(_some_virtual, ::godot::Variant) or GDVIRTUAL1(_some_virtual, const godot::Variant&).

    One thing to note, if I declare a function to return a pointer to Node* or anything derived, then it will work as long as there isn't any argument with such type.

    Inspecting the macro for the declaration of a function with no return and a single argument, there is this:

    method_info.arguments.push_back(::godot::GetTypeInfo<m_type1>::get_class_info());\
    method_info.arguments_metadata.push_back(::godot::GetTypeInfo<m_type1>::METADATA);

    Since the undefined symbol message always contains GetTypeTypeInfo I suspect there is something going on related to GetTypeInfo<Control*> (or anything derived from Node).

  6. dsnopek commented on Jun 10, 2024

    @dsnopek
    Collaborator

    I can reproduce this error!

    I just posted PR #1484 which fixes this in my testing. Please let me know if it works for you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic:gdextension

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions