Compiler errors while following GDNative C tutorial

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By duckowithoutlucko

I’m trying to follow the tutorial that takes you through the GDNative Simple project.
I’ve gotten as far as setting up the folder structure and I created the simple.c file manually (copy and pasted from the snippets in the tutorial) and now I’m attempting to compile for Win10.

I haven’t downloaded the example files from the GD-native examples repository so it’s possible that there’s something I’ve missed from there, but I wanted to ask before trying that as I’m likely to just get more confused.

This is the error log:

D:\Godot-source\GDNative-projects\src>cl /Fosimple.obj /c simple.c /nologo -EHsc -DNDEBUG /MD /I. /I..\godot-headers simple.c 
simple.c(9): error C2143: syntax error: missing '{' before '*' simple.c(23): warning C4133: '=': incompatible types - from 'godot_gdnative_ext_nativescript_api_struct *' to 'int *' 
simple.c(42): error C2223: left of '->godot_nativescript_register_class' must point to struct/union

and the first few lines of simple.c (in case I am actually missing some syntax and I just can’t see it):

#include <gdnative_api_struct.gen.h>
#include <string.h>

typedef struct user_data_struct {
    char data[256];
} user_data_struct;

const godot_gdnative_core_api_struct *api = NULL;
const godot_gdnative_ext_nativescript_api_script *nativescript_api = NULL;

void *simple_constructor(godot_object *p_instance, void *p_method_data);
void simple_destructor(godot_object *p_instance, void *p_method_data, void *p_user_data);
godot_variant simple_get_data(godot_object *p_instance, void *p_method_data,
        void *p_user_data, int p_num_args, godot_variant ** p_args);

void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *p_options) {
    api = p_options->api_struct;

    // Now find our extensions.
    for (int i = 0; i < api->num_extensions; i++) {
        switch (api->extensions[i]->type) {
            case GDNATIVE_EXT_NATIVESCRIPT: {
                nativescript_api = (godot_gdnative_ext_nativescript_api_struct*)api->extensions[i];
            }; break;
            default: break;
        }
    }
}

void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *p_options) {
    api = NULL;
    nativescript_api = NULL;
}

void GDN_EXPORT godot_nativescript_init(void *p_handle) {
    godot_instance_create_func create = { NULL, NULL, NULL };
    create.create_func = &simple_constructor;

    godot_instance_destroy_func destroy = { NULL, NULL, NULL };
    destroy.destroy_func = &simple_destructor;

    nativescript_api->godot_nativescript_register_class(p_handle, "SIMPLE", "Reference",
            create, destroy);

    godot_instance_method get_data = { NULL, NULL, NULL };
    get_data.method = &simple_get_data;

    godot_method_attributes attributes = { GODOT_METHOD_RPC_MODE_DISABLED };

    nativescript_api->godot_nativescript_register_method(p_handle, "SIMPLE", "get_data",
            attributes, get_data);
}

My suspicion is that this is related to gdnative_api_struct.gen.h not linking properly, but I don’t really understand how that works with the file structure that’s given.