GD Extension - CMake - Problems

Godot Version

4.6.1

I keep having trouble using CMake to build a GDExtension.

I’m trying to get an extension to build using CMake and scons, however CMake behaves unpredictably. Before I’ve had it where suddenly CMake would stop working with a message of

Cannot generate into /home/jordan/Code/CPP/gd_one/godot-cpp-template
It was created with incompatible generator 'Unix Makefiles'

Please either delete it manually or select another generation director

When it had been working the day before, and now today I added some code, checked that things were working. And then decided to try and adjust the SConstruct file to try and get things to build and work using scons as well. However after the failed scons build, the CMake project no longer works. It compiles, but when loaded in Godot it starts throwing errors.

ERROR: Condition "!FileAccess::exists(path)" is true. Returning: ERR_FILE_NOT_FOUND
   at: open_dynamic_library (drivers/unix/os_unix.cpp:1061)
ERROR: Condition "!FileAccess::exists(path)" is true. Returning: ERR_FILE_NOT_FOUND
   at: open_dynamic_library (drivers/unix/os_unix.cpp:1061)
ERROR: GDExtension dynamic library not found: 'res://bin/example.gdextension'.
   at: open_library (core/extension/gdextension.cpp:740)
ERROR: Error loading extension: 'res://bin/example.gdextension'.

However the loaded project does have the file:

But if I click on the file I get this error:

  ERROR: drivers/unix/os_unix.cpp:1061 - Condition "!FileAccess::exists(path)" is true. Returning: ERR_FILE_NOT_FOUND
  ERROR: drivers/unix/os_unix.cpp:1061 - Condition "!FileAccess::exists(path)" is true. Returning: ERR_FILE_NOT_FOUND
  ERROR: GDExtension dynamic library not found: 'res://bin/example.gdextension'.
  ERROR: Failed loading resource: res://bin/example.gdextension.
  ERROR: editor/editor_node.cpp:1628 - Condition "res.is_null()" is true. Returning: ERR_CANT_OPEN

I checked the content of the file and it looks fine. Any idea what caused this problem? Or how I can fix it? I used git to roll back all today’s changes but the problem persists.

i see two separate problems.

example.gsextension file tells godot where to find the extension library, its in plain text so open it to see what godot is looking for.

you aren’t properly cleaning up, godot ignores files, git ignores files

so lookup how to reset your source tree including untracked files, delete cmake’s build folder, etc

First of all calling cmake on the build directory with --target clean has no effect on the problem , neither does resetting the cmake cache so it’s not to do with cmake not being “cleaned” properly.

However in case I am wrong can you point me to the docs that describe the proper cleanup as you refer to it, as I don’t see anything here that says specific cleanup steps are needed:

Secondly I did nothing to change anything with cmake at all, the problem just suddenly appeared, one minute it worked fine, the next it had these errors.

I know the file is plain text, note my original post that says I opened the file and it’s contents are basically the same as every other gdextension I built, only the entry point and lib name are different between the different extensions.

Thanks for replying but your post was less than helpful.

So you would see that the gdextension file lists the libraries to load, and godot says it can’t find the one that matches your godot executable. That’s one problem.

The second one is that CMake can still clearly see something it doesn’t like, so why not change your CMake build directory.

If you don’t like my responses, then I’d be OK with not trying to help, its up to you.

I deleted all build directories, and still the same problem. How was deleting it supposed to do something different then using --target clean ?

Why do you say CMake sees something it doesn’t like, the project builds and launches, but then throws the error, so if it builds properly why would it be a problem in cmake? If your refering to my random makefile error, thats not caused by Cmake either I don’t think, it happens in the generated code that gets created from the method calls in the godot-cpp/CMakeLists.txt, and because this happened randomly in three different projects, I just created a build config to run--target clean before building, so now when it happens I just use that build config to fix it.

The only problem I can see in the gdextension file is the name, the extension is longer compiled with the prefix, is this maybe the problem? If so what caused it and how to fix?

Edit:
I tried changing the file name in the gdextension file and it still gives the same error so I don’t think that’s the problem either.

Further Edit:

I found the problem, and it was my own stupidity I guess. At some point before traveling for Easter weekend, I added _bind_methods() to the header file for one object but forgot to add the implementation when I got back. After profiling what was happening I realized the lib file wasn’t being loaded due to an undefined symbol in the object, which led me to realizing the lack of implementation for _bind_methods() . Once I added the method definition to the cpp file for the object, it solved the problem. However to be fair the error message was a bit misleading, which made tracking down the problem difficult.

Secondly I see that if one clones the template, and builds the vanilla template using CMake without making any changes that the error also occurs then. It seems that when using cmake it does not automatically generate the prefix of lib before the target name, and one must explicitly add the lib prefix in the libname of the cmake file which I do not see mentioned anywhere.

I don’t consider that to be true, getting these things to work can be difficult, and small mistakes send us for a loop, don’t worry about it, just add solving it to your big list of problems you’ve solved and let it build your confidence in solving.

Yes I too found there are a lot of error messages that could be better, would require a proposal maybe, an issue, and a pull request to change. I couldn’t find any in the tracker.

I can look into that, since these are two separate repo’s, without CI testing both(which is not setup for cmake) then changes in godot-cpp over time can cause this. It’s pretty low effort/difficulty if you wanted to have a go at updating the template yourself.

But good work finding the problem, turned out to be a bit of an odd ball with the missing function implementation, I wonder if you got any warnings in your compiler output?

They are very different things.

I’d try an explain it but I’d do a terrible job because I am not familiar enough with the subject off the top of my head, and the documentation isn’t easy to find. I’d just be regurgitating something grok gave me if was and you can do that yourself.

I wouldn’t know how to fix the template. It seems to me that if I went to work on it in windows, that my fix is not gonna work as then the library would be created with the lib prefix as that’s the lib name set in the cmake lists file. Whereas the extensions file expects the windows library to not have the lib prefix. So either way one of the library versions would then have an unconventional name.

An no, there were no warnings in either compiler or cmake output.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.