• Godot Help
  • Question about Structuring Code for C++ GDNative 2D Dodge the Creeps Tutorial

Hi there,

I'm planning to work through the "Your First 2D Game" tutorial using GDNative C++ as an option, and just want to make sure that my understanding of how to create this project is correct.

The project setup page has a link to a 'dodge_assets_with_gdnative.zip' file that I downloaded. I also downloaded and generated bindings for the 3.4 version of the godot-cpp and godot-headers repositories. (If I should use a later version of godot-cpp and godot-headers, let me know--I received an error message during a compilation attempt related to a missing 'Godot.hpp' file, so I chose to use 3.4, which has this file, instead of a later version that instead had a 'godot.hpp file.)

I placed the godot-cpp folder within the same folder as the project folder in order to match the setup shown in this completed version of the GDNative C++ dodge_the_creeps project.

My main question is when I should try compiling this folder. My compilation attempts are producing the following error message:

src\entry.cpp(7): fatal error C1083: Cannot open include file: 'hud.hpp': No such file or directory

It looks like this file gets manually created by the user in the process of making the 'dodge the creeps' game, so my guess is that I'm not supposed to try to compile the project until I have created all the required .cpp and .hpp files. Is that correct, or is there a way to compile them earlier?

Thanks in advance for your help!

  • DaveTheCoder replied to this.
  • It looks like the problem lay with the entry.cpp file provided in the 'dodge_assets_with_gdnative.zip' file. The entry.cpp file contained the following lines:

    // Uncomment these lines when you create these files.
    #include "hud.hpp"
    #include "main.hpp"
    #include "mob.hpp"
    #include "player.hpp"

    I realized that these lines were not commented out, which was the cause of the compiling error: the compiler was looking for a file (hud.hpp) that hadn't yet been created. I fixed this problem by putting a double slash before each include item:

    // Uncomment these lines when you create these files.
    // #include "hud.hpp"
    // #include "main.hpp"
    // #include "mob.hpp"
    // #include "player.hpp"

    After doing so, the compilation command ran successfully.

    Perhaps the 'dodge_assets_with_gdnative.zip' file could also be updated to resolve this issue.

    5 days later

    kburchfiel my guess is that I'm not supposed to try to compile the project until I have created all the required .cpp and .hpp files

    That sounds reasonable, although I haven't attempted the GDNative C++ version of that project. I hadn't even noticed that was provided.

    I'd say that it's best to use the version of Godot (Godot 3.4.3-stable) that matches the tutorial.

    It looks like the problem lay with the entry.cpp file provided in the 'dodge_assets_with_gdnative.zip' file. The entry.cpp file contained the following lines:

    // Uncomment these lines when you create these files.
    #include "hud.hpp"
    #include "main.hpp"
    #include "mob.hpp"
    #include "player.hpp"

    I realized that these lines were not commented out, which was the cause of the compiling error: the compiler was looking for a file (hud.hpp) that hadn't yet been created. I fixed this problem by putting a double slash before each include item:

    // Uncomment these lines when you create these files.
    // #include "hud.hpp"
    // #include "main.hpp"
    // #include "mob.hpp"
    // #include "player.hpp"

    After doing so, the compilation command ran successfully.

    Perhaps the 'dodge_assets_with_gdnative.zip' file could also be updated to resolve this issue.

      kburchfiel Perhaps the 'dodge_assets_with_gdnative.zip' file could also be updated to resolve this issue.

      That's not likely to happen unless it's reported as an issue on the tracker, or you submit the fix yourself.

      Since GDNative is being replaced by GDExtension in Godot 4.x, that might affect the priority.