I've written a getting started in GDNative C++ tutorial
gamedevadventures.posthaven.com/using-c-plus-...Posted Mar 13, 2018, 10:47 AM UTC
Posted Mar 13, 2018, 10:47 AM UTC
Interesting. Good to know the gdnlib files can be made from the engine directly, although it's weird that you have to input the file type directly rather you being given an option of some sort...
Looking forward to part 2!
Yeah, the UX definitely could do with some work. I also found creating and saving resources from the inspector to be weird, I mean, to me, the inspector looks like a properties window for the selected node, not something completely independent and ctrl/cmd-s doesn’t save it, you have to manually do it from the inspector, which was a big source of errors for me when I first did this last week. I’m also a little confused still about .tres vs .gdnlib, from what I’ve read, .gdnlib is the newer one and supercedes .tres for GDNative, yet the editor defaults to .tres when you go to save it (I guess because .tres is the generic resource file type, but still...).
Part 2 should be ready tomorrow :)
Hm, I know that meta+s saves the scene AND the script, so maybe it would be a good idea to have it save the Inspector resource as well, assuming there is one already.
I think the end-goal is for the NativeScript C++ process to be as painless as possible. I'd want us to be able to just write C++ in whatever editor we want, and then switch over to Godot, run the scene, have it automatically recompile the libraries, and then execute. And ideally creating new scripts would be a semi-automated process too.
Wanna also create a little wizard for creating plugins so that the process is easier.
I know there is a GitHub Issue about allowing the ScriptEditor to edit files more freely (files of all types), and then we'd be able to edit ConfigFile and JSON files too. There's just so much to do to make the engine as awesome as possible and not enough time. Sigh
Indeed.
A slightly different solution might be to have the build process of the GDNative lib generate the .gdns and .gdnlib files automagically, although for the .gdns file, I’m not quite sure how. Maybe Godot should just attempt to autodetect if a .gdnlib-defined library containes the godot_nativescript_init symbol and automatically and transparently handle NativeScript in that case, since the init already registers the classes, why do we even need to register them in .gdns files too? (and then have the attach script dialog simply know about these native classes). Just some idle thoughts, I guess.
Thank you!
Trying to compile your simple.cpp file using scons p=linux gave me this error: /usr/bin/ld: cannot find -lgodot-cpp
Can you check the content of your godot-cpp directory? Specifically, inside the bin/? You should see a file libgodot-cpp.a, if you don't then something isn't right. Let me know and I'll try to help you (and update the tutorial).
The only thing in my godot-cpp/bin directory is libgodot-cpp.linux.64.a
Ahh! Quick fix for now is to change line 46 of the SConstruct file in simple to env.Append(LIBS=['godot-cpp.linux.64']). I'll update the tutorial when I determine the best way to make sure this works cross platform.
Yeah, that fixed it. Thanks.
I'm hitting an error when building the godot-cpp files.
Running:
scons godotbinpath="/usr/bin/godot" platform=linux use_llvm=yes
Output:
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
clang++ -o src/core/Transform.o -c -fPIC -g -O3 -std=c++14 -Wwrite-strings -m64 -I. "-I/home/UNAME/Devel/Godot/CPP Test/godot_headers" -Iinclude -Iinclude/core src/core/Transform.cpp
In file included from src/core/Transform.cpp:1:
In file included from include/core/Transform.hpp:4:
In file included from include/core/Basis.hpp:6:
In file included from include/core/Vector3.hpp:6:
include/core/String.hpp:4:10: fatal error: 'gdnative/string.h' file not found
#include <gdnative/string.h>
^~~~~~~~~~~~~~~~~~~
1 error generated.
scons: *** [src/core/Transform.o] Error 1
scons: building terminated because of errors.
Any idea what I'm doing wrong? This is running on Manjaro with Godot installed from the AUR.
gdnative/string.h should be found in your godot_headers directory. Can you check that your godot_headers directory is indeed here: /home/UNAME/Devel/Godot/CPP Test/godot_headers and then check that it contains a gdnative subdirectory, with string.h inside?
I had the same issue but solved it by writing
headers=../godot_headers
although it doesn't change for the default path. However I have another issue when compiling
simple
, when running
scons platform=osx use_llvm=yes
I get the error
-dynamiclib simple.os -L/Users/*username*/godotmodules/godot-cpp/bin -lgodot-cpp
`ld: library not found for -lgodot-cpp`
I have not found anything about that anywhere. Any idea what's missing?
Did you compile godot-cpp? Check /Users/*username*/godotmodules/godot-cpp/bin and you should see libgodot-cpp.a. If not, then something isn't setup correctly. Did you miss an installation step by accident maybe?
Ah! it seemed that mine was named libgodot-cpp.osx.64.a for some reason. I changed the SConstruct and it works like a charm now ! Thanks again for the tutorial !
That was the issue! I downloaded the repositories from the Github website rather than cloning them so it added "-master" to the end of each directory name. Sorry for the dumb issue. Thanks for the help. It seems to be building fine now.
Great! I'm glad you've got it working :) I've added a note to the tutorial, and added how you can override this in case you wish to name them something else or take them from a different directory (as you may wish to do if you built Godot from source and want to make sure you have the newest headers).
Awesome!