How should you compile a GDNative module using MINGW64?

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

Hello everyone.

I’ve been working through the GDNative C example tutorial in the documentation and I’m having trouble compiling the module. I am using a Windows computer and MinGW-W64 (msys2). I’m new to GCC, and DLLs in general, so please forgive me if this is a stupid question.
The -rdynamic option isn’t recognized in this environment, and trying to compile with that option fails, so I tried to use -Wl,–export-all-symbols instead. There are no errors after that, however, when I run the project and click the button, I get the error “Invalid call. Nonexistent function ‘get_data’ in base 'NativeScript”.
These are the exact commands that I have used to compile the project:

gcc -std=c11 -fPIC -c -I../godot_headers simple.c -o simple.o

gcc -Wl,--export-all-symbols -shared simple.o -o ../simple/bin/libsimple.dll

What could be going wrong here?

:bust_in_silhouette: Reply From: omggomb

Disclaimer: I have no idea what I’m doing :smiley:

Just leaving out -rdynamic, with the rest of the commands identical to the docs works for me.

Looking at Link Options (Using the GNU Compiler Collection (GCC)) it seems to me that this option is not for windows (“on platforms that support it”).

From this stack overflow c - What exactly does `-rdynamic` do and when exactly is it needed? - Stack Overflow I gather that it is more for executables than for libraries.

I got it working!
You are correct that leaving out both -rdynamic and -Wl,--export-all-symbols seems to work just fine on Windows.

The problem was actually in my script and had nothing to do with my compilation steps. All this time I thought that the symbols weren’t getting exported correctly because I was using some wrong combination of options on the command line. I feel so embarrassed right now. Thank you so very much for the help though! I really appreciate it.

ihsan | 2021-08-18 06:28