godotengine / godot-docs

Godot Engine official documentation
https://docs.godotengine.org
Other
3.78k stars 3.07k forks source link

GDNative does not work for Windows from Linux at all #3463

Open diocore opened 4 years ago

diocore commented 4 years ago

Your Godot version: 3.2 Issue description: Hi, okay, I've got a couple of issues here: first of the SConstruct file does not work for 3 reasons:

  1. The flags for the c compilation don't exist. I changed them to the once recommended from my console. image after fixing this scons uses g++ instead of mingw even though I did all steps to ensure the usage of mingw as written in the documentation. this is the line I use for compilation: scons platform=windows generate_bindings=yes use_mingw=yes bits=64

this is maybe because the flags are for the MSVC and not for mingw but according to the documentation and in order to be able to cross compile from linux to windows mingw should be used.

after fixing this editing the SConstruct so it is forced to use mingw by adding:

env = Environment(tools = ['mingw'])
env.Replace(CXX='/usr/bin/x86_64-w64-mingw32-g++',
            LINK='/usr/bin/x86_64-w64-mingw32-g++')

it uses mingw and has no problems anymore with the flags.

  1. scons successfully builds using mingw and uses all the right flags and all and puts a .so file in demo/bin/win64. Yeaj an .so file.... with the platform chosen for windows and compilation with Why? probably because the SConstruct is wrong again. Console output:

    scons: Reading SConscript files ...
    scons: done reading SConscript files.
    scons: Building targets ...
    /usr/bin/x86_64-w64-mingw32-g++ -DEBUG -shared -o demo/bin/win64/libgdexample.so src/gdexample.o src/gdlibrary.o -Lgodot-cpp/bin -lgodot-cpp.windows.debug.64 -Wl,--out-implib,demo/bin/win64/libgdexample.a
    scons: done building targets.

    which clearly states -o demo/bin/win64/libgdexample.so so after renaming the file ending to .dll and checking it with a dll checker, everything seems fine: image

  2. After creating the gdnativelibrary.gdnlib and the nativescript.gdns as described in the documentation I get the following error upon execution: image

so... at this point and after so many errors in the files and building process I'm at a point at which I wonder if I'm doing something totally wrong or If it had ever been tested by someone before posting it...

I even wanted to try the complete example which is referenced here https://docs.godotengine.org/en/3.2/tutorials/plugins/gdnative/gdnative-cpp-example.html at the end of the introduction just to check whether or not it worked if someone else built the dynamic libraries just to find out that there are not libraries pre-build to test it.

I hope someone can help me because gdnative libraries is a part of my bachelor thesis, or to put it in another way I want to use it to demonstrate my bachelor thesis as well as in a game I'm building.

URL to the documentation page: https://docs.godotengine.org/en/3.2/tutorials/plugins/gdnative/gdnative-cpp-example.html

BastiaanOlij commented 4 years ago

I think the problem is that the instructions were written for Visual C++, not MINGW which indeed requires different switches.

I don't use MINGW so I don't know what it should have as switches but looking at the SConstruct file of Godot-cpp we might find some clues:

        # MinGW
        if env['bits'] == '64':
            env['CXX'] = 'x86_64-w64-mingw32-g++'
        elif env['bits'] == '32':
            env['CXX'] = 'i686-w64-mingw32-g++'

        env.Append(CCFLAGS=['-g', '-O3', '-std=c++14', '-Wwrite-strings'])
        env.Append(LINKFLAGS=['--static', '-Wl,--no-undefined', '-static-libgcc', '-static-libstdc++'])

I think the -Wwrite-strings might have something to do with making sure symbols are properly exported?

diocore commented 4 years ago

that could probably work. My main issue is that even if I build the files, which are built correctly afaik (checked with a dll checker) that I can't get it to work with these files and gdnative libs. Godot says it is missing init_library() and there is no example in the docs. I'd really like to see it run at least once so I could test what the problem is. Could you provide a .dll file for godot, so I can test it in my project maybe?