godotengine / godotengine/godot-cpp
Building with build_profile containing only `Object`, `Resource` and `Image` fails to link
- Dominant language
- C++
- Stars
- 2.7k
- Forks
- 809
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 8
Description
### Godot version
4.4
### godot-cpp version
27ffd8c6be614b283b1228c3f8476db25070c00f
### System information
Windows, 64-bit, MSVC
### Issue description
I started using a build_profile restricting classes to the following:
```json
{
"enabled_classes": [
"Object",
"Resource",
"Image"
]
}
```
First I was surprised at the sheer amount of classes it still tried to build, only to realize `Resource` has a method returning a `Node*`, so I guess it tried to include Node too, which then refers to `Window`, which refers to `Theme`, which refers to a bunch of other things.
But then, it fails to link:
https://github.com/Zylann/godot_fast_noise_2/actions/runs/12416475481/job/34665187777
```
Linking Shared Library project\addons\zylann.fastnoise2\bin\libgdfastnoise2.windows.template_release.x86_64.dll ...
libgodot-cpp.windows.template_release.x86_64.lib(variant.windows.template_release.x86_64.obj) : error LNK2001: unresolved external symbol "public: virtual struct godot::AABB __cdecl godot::VisualInstance3D::_get_aabb(void)const " (?_get_aabb@VisualInstance3D@godot@@UEBA?AUAABB@2@XZ)
libgodot-cpp.windows.template_release.x86_64.lib(variant_internal.windows.template_release.x86_64.obj) : error LNK2001: unresolved external symbol "public: virtual struct godot::AABB __cdecl godot::VisualInstance3D::_get_aabb(void)const " (?_get_aabb@VisualInstance3D@godot@@UEBA?AUAABB@2@XZ)
project\addons\zylann.fastnoise2\bin\libgdfastnoise2.windows.template_release.x86_64.dll : fatal error LNK1120: 1 unresolved externals
scons: *** [project\addons\zylann.fastnoise2\bin\libgdfastnoise2.windows.template_release.x86_64.dll] Error 1120
scons: building terminated because of errors.
```
Somehow it got to compile code that calls `VisualInstance3D::_get_aabb`, but my extension doesn't even use nodes.
To workaround it, I have to add `VisualInstance3D` to the profile (which in total builds 63 classes, so still a good win compared to 744, but far from the 3 I actually use).
For sure maybe a fix should be done to detect that `VisualInstance3D` is also needed somehow.
But I think that class list is doing too much. Too many classes are picked. Yes, Resource has a method that returns `Node`. *But I don't need to compile Node, because I don't use it, and Node is forward-declared anyways*. So GodotCpp should not try to include it to classes it has to compile.
The only classes GodotCpp should implicitely generate, are classes that need to be *defined*. So pretty much base classes, AFAIK. The rest should not need to be defined (such as methods taking objects or returning objects, because those are forward-declared).
### Steps to reproduce
Compile GodotCpp on Windows with the listed build profile.
### Minimal reproduction project
N.A
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.