Skip to content

GDExtension C Example: ODR violations in api.h #11387

@charjr

Description

@charjr

Following the GDExtension C example leads to compilation errors with scons due to multiple definition warnings.

These errors are specific to the api, constructors and destructors variables defined in api.h which break the one definition rule by defining variables inside a header file:

.. code-block:: c
#pragma once
/*
This file works as a collection of helpers to call the GDExtension API
in a less verbose way, as well as a cache for methods from the discovery API,
just so we don't have to keep loading the same methods again.
*/
#include "gdextension_interface.h"
#include "defs.h"
extern GDExtensionClassLibraryPtr class_library;
// API methods.
struct Constructors
{
GDExtensionInterfaceStringNameNewWithLatin1Chars string_name_new_with_latin1_chars;
} constructors;
struct Destructors
{
GDExtensionPtrDestructor string_name_destructor;
} destructors;
struct API
{
GDExtensionInterfaceClassdbRegisterExtensionClass2 classdb_register_extension_class2;
} api;
void load_api(GDExtensionInterfaceGetProcAddress p_get_proc_address);

My suspicion is that these variables should be static, however I cannot confirm that because I have not managed to compile a working extension.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions