godotengine / godot-cpp

C++ bindings for the Godot script API
MIT License
1.75k stars 580 forks source link

I dont have a Reference.hpp? #136

Closed atsuzaki closed 6 years ago

atsuzaki commented 6 years ago

I'm trying to setup GDNative-demos with cpp, figured to ask here instead of there since Reference.hpp seems to be something provided by this repo.

I have generated the cpp_bindings according to the README.md. Platform is linux, and I pulled this repo from commit 94ec3119240461831a46264f1465a515070706c7

ayaka@DESKTOP-33AK5VQ:/mnt/c/Users/Ayaka/Documents/GDNative-demos/cpp/kinematic_character/Script$ scons
 platform=linux
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o src/colworld.os -c -g -O3 -std=c++14 -Wno-writable-strings -fPIC -Isrc/godot_headers -Isrc/cpp_bindings/include -Isrc/cpp_bindings/include/core -Isrc src/colworld.cpp
In file included from src/cpp_bindings/include/core/Godot.hpp:13:0,
                 from src/colworld.h:20,
                 from src/colworld.cpp:17:
src/cpp_bindings/include/core/Ref.hpp:6:28: fatal error: ../Reference.hpp: No such file or directory
compilation terminated.
scons: *** [src/colworld.os] Error 1
scons: building terminated because of errors.

Doing find . -name Reference.hpp came up blank as well.

karroffel commented 6 years ago

Did you generate the API bindings when compiling the godot-cpp repo?

atsuzaki commented 6 years ago

The part where you do scons godotbinpath="../godot_fork/bin/godot_binary" p=linux? Yes. Actually forced it to regenerate bindings twice before posting this issue

karroffel commented 6 years ago

Then the file include/Reference.hpp should exist. If not then that's veeeeeeery weird. Can you double check the include paths?

atsuzaki commented 6 years ago

Re-cloned and tried the whole process again.

ayaka@DESKTOP-33AK5VQ:/mnt/c/Users/Ayaka/Documents/GDNative-demos/cpp/kinematic_character/Script/src/godot-cpp$ scons godotbinpath="~/Godot_v3.0.2-stable_mono_x11_64" p=linux
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o src/core/AABB.o -c -fPIC -g -std=c++14 -Wwrite-strings -Og -m64 -I. I/mnt/c/Users/Ayaka/Documents/GDNativedemos/cpp/kinematic_character/Script/src/godot_headers -Iinclude -Iinclude/core src/core/AABB.cpp
g++ -o src/core/Array.o -c -fPIC -g -std=c++14 -Wwrite-strings -Og -m64 -I. -I/mnt/c/Users/Ayaka/Documents/GDNativedemos/cpp/kinematic_character/Script/src/godot_headers -Iinclude -Iinclude/core src/core/Array.cpp
g++ -o src/core/Basis.o -c -fPIC -g -std=c++14 -Wwrite-strings -Og -m64 -I. -I/mnt/c/Users/Ayaka/Documents/GDNativedemos/cpp/kinematic_character/Script/src/godot_headers -Iinclude -Iinclude/core src/core/Basis.cpp
g++ -o src/core/Color.o -c -fPIC -g -std=c++14 -Wwrite-strings -Og -m64 -I. -I/mnt/c/Users/Ayaka/Documents/GDNative-demos/cpp/kinematic_character/Script/src/godot_headers -Iinclude -Iinclude/core src/core/Color.cpp
g++ -o src/core/Dictionary.o -c -fPIC -g -std=c++14 -Wwrite-strings -Og -m64 -I. -I/mnt/c/Users/Ayaka/Documents/GDNative-demos/cpp/kinematic_character/Script/src/godot_headers -Iinclude -Iinclude/core src/core/Dictionary.cpp
g++ -o src/core/GodotGlobal.o -c -fPIC -g -std=c++14 -Wwrite-strings -Og -m64 -I. -I/mnt/c/Users/Ayaka/Documents/GDNative-demos/cpp/kinematic_character/Script/src/godot_headers -Iinclude -Iinclude/core src/core/GodotGlobal.cpp
g++ -o src/core/NodePath.o -c -fPIC -g -std=c++14 -Wwrite-strings -Og -m64 -I. -I/mnt/c/Users/Ayaka/Documents/GDNativedemos/cpp/kinematic_character/Script/src/godot_headers -Iinclude -Iinclude/core src/core/NodePath.cpp
g++ -o src/core/Plane.o -c -fPIC -g -std=c++14 -Wwrite-strings -Og -m64 -I. -I/mnt/c/Users/Ayaka/Documents/GDNativedemos/cpp/kinematic_character/Script/src/godot_headers -Iinclude -Iinclude/core src/core/Plane.cpp
g++ -o src/core/PoolArrays.o -c -fPIC -g -std=c++14 -Wwrite-strings -Og -m64 -I. -I/mnt/c/Users/Ayaka/Documents/GDNativedemos/cpp/kinematic_character/Script/src/godot_headers -Iinclude -Iinclude/core src/core/PoolArrays.cpp
g++ -o src/core/Quat.o -c -fPIC -g -std=c++14 -Wwrite-strings -Og -m64 -I. -I/mnt/c/Users/Ayaka/Documents/GDNativedemos/cpp/kinematic_character/Script/src/godot_headers -Iinclude -Iinclude/core src/core/Quat.cpp
g++ -o src/core/Rect2.o -c -fPIC -g -std=c++14 -Wwrite-strings -Og -m64 -I. -I/mnt/c/Users/Ayaka/Documents/GDNativedemos/cpp/kinematic_character/Script/src/godot_headers -Iinclude -Iinclude/core src/core/Rect2.cpp
g++ -o src/core/RID.o -c -fPIC -g -std=c++14 -Wwrite-strings -Og -m64 -I. -I/mnt/c/Users/Ayaka/Documents/GDNativedemos/cpp/kinematic_character/Script/src/godot_headers -Iinclude -Iinclude/core src/core/RID.cpp
g++ -o src/core/String.o -c -fPIC -g -std=c++14 -Wwrite-strings -Og -m64 -I. -I/mnt/c/Users/Ayaka/Documents/GDNativedemos/cpp/kinematic_character/Script/src/godot_headers -Iinclude -Iinclude/core src/core/String.cpp
g++ -o src/core/Transform.o -c -fPIC -g -std=c++14 -Wwrite-strings -Og -m64 -I. -I/mnt/c/Users/Ayaka/Documents/GDNativedemos/cpp/kinematic_character/Script/src/godot_headers -Iinclude -Iinclude/core src/core/Transform.cpp
g++ -o src/core/Transform2D.o -c -fPIC -g -std=c++14 -Wwrite-strings -Og -m64 -I. -I/mnt/c/Users/Ayaka/Documents/GDNativedemos/cpp/kinematic_character/Script/src/godot_headers -Iinclude -Iinclude/core src/core/Transform2D.cpp
g++ -o src/core/Variant.o -c -fPIC -g -std=c++14 -Wwrite-strings -Og -m64 -I. -I/mnt/c/Users/Ayaka/Documents/GDNativedemos/cpp/kinematic_character/Script/src/godot_headers -Iinclude -Iinclude/core src/core/Variant.cpp
g++ -o src/core/Vector2.o -c -fPIC -g -std=c++14 -Wwrite-strings -Og -m64 -I. -I/mnt/c/Users/Ayaka/Documents/GDNativedemos/cpp/kinematic_character/Script/src/godot_headers -Iinclude -Iinclude/core src/core/Vector2.cpp
g++ -o src/core/Vector3.o -c -fPIC -g -std=c++14 -Wwrite-strings -Og -m64 -I. -I/mnt/c/Users/Ayaka/Documents/GDNativedemos/cpp/kinematic_character/Script/src/godot_headers -Iinclude -Iinclude/core src/core/Vector3.cpp
ar rc bin/libgodot-cpp.linux.64.a src/core/AABB.o src/core/Array.o src/core/Basis.o src/core/Color.o src/core/Dictionary.o src/core/GodotGlobal.o src/core/NodePath.o src/core/Plane.o src/core/
PoolArrays.o src/core/Quat.o src/core/Rect2.o src/core/RID.o src/core/String.o src/core/Transform.o src/core/Transform2D.o src/core/Variant.o src/core/Vector2.o src/core/Vector3.o
ranlib bin/libgodot-cpp.linux.64.a
scons: done building targets.
ayaka@DESKTOP-33AK5VQ:/mnt/c/Users/Ayaka/Documents/GDNative-demos/cpp/kinematic_character/Script/src/godot-cpp$ find . -name Reference.hpp
ayaka@DESKTOP-33AK5VQ:/mnt/c/Users/Ayaka/Documents/GDNative-demos/cpp/kinematic_character/Script/src/godot-cpp$

As you can see, finding Reference.hpp returned blank

karroffel commented 6 years ago

you don't need the godotbinpath anymore but what you do need is generate_bindings=yes, otherwise it won't generate the file

atsuzaki commented 6 years ago

Yep, what you suggested works. Maybe this is a good time to update the README before more issues like mine pop up around here.

Kowbell commented 6 years ago

Err, I still have no Reference.hpp anywhere, even with generate_bindings=yes. Full command: scons p=linux regenerate_bindings=yes

The godot_headers submodule was initialized/updated and my build output came clean with no errors:


scons: done reading SConscript files.
scons: Building targets ...
ar rc bin/libgodot-cpp.linux.64.a src/core/PoolArrays.o src/core/AABB.o src/core/Transform2D.o src/core/Dictionary.o src/core/Basis.o src/core/Quat.o src/core/Color.o src/core/NodePath.o src/core/String.o src/core/Array.o src/core/Variant.o src/core/Transform.o src/core/GodotGlobal.o src/core/RID.o src/core/Plane.o src/core/Vector3.o src/core/Rect2.o src/core/Vector2.o
ranlib bin/libgodot-cpp.linux.64.a
scons: done building targets.```

For what it's worth, `use_llvm=yes` fails with

```scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
clang++ -o src/core/PoolArrays.o -c -fPIC -g -std=c++14 -Wwrite-strings -Og -m64 -I. -Igodot_headers -Iinclude -Iinclude/core src/core/PoolArrays.cpp
error: invalid integral value 'g' in '-Og'
error: invalid integral value 'g' in '-Og'
scons: *** [src/core/PoolArrays.o] Error 1
scons: building terminated because of errors.```

Up to date with 74d0106.
snakeskinsalamander commented 6 years ago

You can add -v so you can get more detail. Maybe it is not pointing to the correct directory. Include godot-cpp/include and godot-cpp/include/core

Kowbell commented 6 years ago

Sorry, add -v to which command? Scons doesn't have a -v for verbose, though adding VERBOSE=1 to the command (scons p=linux regenerate_bindings=yes VERBOSE=1) resulted in output identical to what is shown above.

And where should I add those includes? To whatever file I'm trying to use GDNative for? Reference.hpp does not exist anywhere within my godot-cpp/ directory, so that wouldn't change anything.

mkylmamaa commented 6 years ago

I had the same problem, but generate_bindings=yes did fix it, the file is found at path: godot-cpp/include/Reference.hpp. Would be nice to update the README.

Byteron commented 6 years ago

I do have the same problem. And I did generate the bindings. But I can see that the file is in "include/gen/Reference.hpp"

BastiaanOlij commented 6 years ago

It's possible there are older files still stuck after the move. This is one of the reasons we've placed the generated files into the gen subfolders. We don't remove files that are no longer valid so in this way it's easier to clean up. There may be a file there generated by an older version that is no longer valid that has the old link in it.

Make sure there are no files in the root of the include and src folders, and maybe just delete the files (except from the .gitignore file) from the gen folders and rebuild.

Byteron commented 6 years ago

I followed the C++ example on the docs. I now have "module/godot_headers/" (clone), "module/godot-cpp/" (clone) and "module/godot-cpp/godot_headers/" which is empty. This way it doesn't compile the godot-cpp bindings at all. When I copy the "module/godot_headers/" into "module/godot-cpp/godot_headers/" it works though.

But only the bindings compile. The module itself still says a "Reference.hpp" is missing

BastiaanOlij commented 6 years ago

Those are very old instructions, from before we moved godot_headers into the module. You have to clone godot_cpp recursively so it pulls in the headers as well.

The instructions on the latest version of the docs is pretty accurate as far as building is concerned: https://docs.godotengine.org/en/latest/tutorials/plugins/gdnative/gdnative-cpp-example.html

But this hasn't been updated for nativescript yet so have a look at the read me in the main repo for the changes: https://github.com/GodotNativeTools/godot-cpp

I hope to have time to update the docs for the new syntax soon

Byteron commented 6 years ago

Okay. With the new instructions I get this error: /usr/bin/ld: cannot find -llibgodot-cpp.linux.debug.64.a using clang -o bin/MapBuilder.so -shared src/init.os -Lgodot-cpp/bin -llibgodot-cpp.linux.debug.64.a

BastiaanOlij commented 6 years ago

yes, that was a recent change as well, the libraries are now always prefixed with libgodot-cpp instead of godot-cpp so you need to adjust your projects SConstruct file to match.

Byteron commented 6 years ago

it still doesn't work. T_T Modified the SConstruct file:

env.Append(CPPPATH=['.', 'src/', "godot-cpp/godot_headers/", 'godot-cpp/include/gen/', 'godot-cpp/include/core/'])
env.Append(LIBPATH="godot-cpp/bin")
env.Append(LIBS=["libgodot-cpp" + "." + platform + "." + str(bits)])

using clang -o bin/MapBuilder.so -shared src/init.os -Lgodot-cpp/bin -llibgodot-cpp.linux.64.a i get the same error: /usr/bin/ld: cannot find -libgodot-cpp.linux.64.a

using scons platform=linux it gives me this error:

In file included from godot-cpp/include/core/Ref.hpp:6,
                 from godot-cpp/include/core/Godot.hpp:13,
                 from src/map_builder.hpp:4,
                 from src/init.cpp:1:
godot-cpp/include/gen/Reference.hpp:8:10: fatal error: core/CoreTypes.hpp: No such file or directory
 #include <core/CoreTypes.hpp>
          ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
scons: *** [src/init.os] Error 1
Byteron commented 6 years ago

okay, I think now I got it. Just had to include some more random directories.

BastiaanOlij commented 6 years ago

check what files are in godot-cpp/bin, there may be more to the name change, and indeed you have to make sure include/core and include/gen are in your include search path

Byteron commented 6 years ago

I had to include "include/core", "include/gen" and "include/" because some of the .hpp files in "/core" use #include <core/*.hpp>

With that scons platform=linux worked. the clang compilations still didn't work though.

BastiaanOlij commented 6 years ago

@karroffel @Byteron has a good point here, we either need to clean up the includes and remove the core/ prefix, or go the other way and consistently add core/ and gen/ to the includes so we only need to include the include folder. It's getting a little messy here...

Byteron commented 6 years ago

I assume I need a 3.1 build to use my GDNS? In 3.0.6, I just get a null instance error when I try to do var map_builder = load("res://bin/gdmaploader.gdns").new()

BastiaanOlij commented 6 years ago

Yes, if you want to build a GDNative module that works in 3.0 and 3.1 you need to use the 3.0 branch and follow the much older instructions.

The master of godot-cpp is Godot 3.1 only

BastiaanOlij commented 6 years ago

@atsuzaki original question I believe has been answered and the current readme in master has been updated to reflect a working example and inform about the different branches, so I'm closing this issue as resolved. Thanks for the discussion everyone!