Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding fails on Windows using Ninja + Clang #1250

Open
BoHomola opened this issue Sep 22, 2023 · 2 comments · May be fixed by #1651
Open

Binding fails on Windows using Ninja + Clang #1250

BoHomola opened this issue Sep 22, 2023 · 2 comments · May be fixed by #1651

Comments

@BoHomola
Copy link

BoHomola commented Sep 22, 2023

Godot version

4.1.1 stable

godot-cpp version

4.1.1 stable 1009da4

System information

Windows 11

Issue description

When trying to compile godot_cpp + my lib that includes godot_cpp using clang and ninja on Windows 11,
when calling

godot::ClassDB::bind_method(...)

I get a compile error

In file included from C:/Users/user/dev/project/GDClient/src/MyClass.h:11:
In file included from C:/Users/user/dev/project/build/libs/godot-cpp/gen/include\godot_cpp/classes/engine.hpp:43:
In file included from C:/Users/user/dev/project/libs/godot-cpp/include\godot_cpp/core/class_db.hpp:38:
C:/Users/user/dev/project/libs/godot-cpp/include\godot_cpp/core/method_bind.hpp:506:49: error: cannot reinterpret_cast from member pointer type 'godot::NodePath (MyClass::)()' to member pointer type 'godot::NodePath (godot::_gde_UnexistingClass::)()' of different size
MethodBind a = memnew((MethodBindTR<R, P...>)(reinterpret_cast<R (MB_T::)(P...)>(p_method)));

On Linux CMake + Ninja + Clang works flawlessly.

I tried to look where to issue could be occurring. I found out when I remove MSVC condition from CMakeLists.txt:157

from:

target_compile_definitions(${PROJECT_NAME} PUBLIC
	$<$<CONFIG:Debug>:
		DEBUG_ENABLED
		DEBUG_METHODS_ENABLED
	>
	$<${compiler_is_msvc}:
		TYPED_METHOD_BIND
	/>
)

to:

target_compile_definitions(${PROJECT_NAME} PUBLIC
	$<$<CONFIG:Debug>:
		DEBUG_ENABLED
		DEBUG_METHODS_ENABLED
	>		
        TYPED_METHOD_BIND
)

This effectively resolved the errors and got a successful build.
Although I am not really sure if that fixes things properly and does not create issues elsewhere.

Steps to reproduce

  1. Link godot_cpp to your library
  2. Bind one of your methods using godot::ClassDB::bind_method
  3. Run CMake with build system Ninja and compiler Clang

Minimal reproduction project

N/A

@enetheru
Copy link
Contributor

Note to self: Read linked merge requests before spending the morning looking into an issue.

I have successfully re-produced your error with a fresh download of llvm binaries.

"When Clang compiles C++ code for Windows, it attempts to be compatible with MSVC. There are multiple dimensions to compatibility." MSVCCompatibility

And the associated godotengine issue

adding TYPED_METHOD_BIND to the definitions solves the compile error

@enetheru enetheru linked a pull request Nov 24, 2024 that will close this issue
@enetheru
Copy link
Contributor

This will be resolved by PR #1651

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants