-
-
Notifications
You must be signed in to change notification settings - Fork 603
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
Visual Studio 2022 GDExtension C++ ".lib" binding error #1327
Comments
Did you compile both with |
Yes, sorry... sorry I was wrong... The problem is with GDextension. |
Where do I add that? When do I generate the bindings in godot cpp? I mean, it would be like this.
|
Yes, I'm unsure exactly what's wrong here, will look when I have time 🙂 |
It seems that there is a problem with the generation of the binding that generates an incompatibility with VScode. I leave a mini video showing the problem |
I also want to say that I have this project running in VScode for both Windows and Linux Ubuntu and it works very well there. https://gitlab.com/kone9/godot-engine-4.2-template-gdextension-with-vscode-windows-11 |
Will it be possible to generate the .lib directly from Visual Studio without using Scons??? |
#1319 fixes this. You have to build |
There is no possibility of compiling the static library directly with Visual Studio? I know that in Linux the process is easy, but in Windows it would be much simpler to have a template with Visual Studio and be able to generalize both the DLL and the static library... I'm going Let's try this and see if it works for me
But I insist, you don't know how to configure visual studio to generate the static library directly from visual studio? |
I mean I don't see the point in using VS for |
You have to download scons, python and make configurations that waste your time. Many people have already told me that they are not encouraged with C++ godot or that it is not worth the effort to learn the procedure with GDextension and C++ because the configuration is a lot of work, I mean apart from that there is the whole issue of including libraries, configuring the dubug with visual studio, etc.. That's why I think the ideal would be to have a repository with a Visual Studio 2022 project that already contains the Godot-Cpp and even a built-in godot engine editor so that by simply touching a button you can generate the bindings and with another button run the game or the direct editor from visual studio.. |
You know, I just compiled with the command you sent in debug mode, but it still doesn't work, I'm testing it in this project. scons platform=windows custom_api_file="gdextension\extension_api.json" target=template_debug use_static_cpp=no optimize=debug debug_symbols=yes https://gitlab.com/kone9/visual-studio-godot-engine-gdextension-cpp-template |
You need to rebuild |
Build started at 20:31... |
No, you need to build |
scons platform=windows custom_api_file="gdextension\extension_api.json" target=template_debug use_static_cpp=no optimize=debug debug_symbols=yes scons platform=windows custom_api_file="gdextension\extension_api.json" target=template_release use_static_cpp=no optimize=speed debug_symbols=yes |
Quickly try my project, I have already compiled the static libraries and uploaded them to the repository, you will see that it does not work. https://gitlab.com/kone9/visual-studio-godot-engine-gdextension-cpp-template |
And remove Also for Windows you have to add |
What do you mean by Also "for Windows you have to add TYPED_METHOD_BIND and NOMINMAX to the preprocessor." Where is that added? .. In the windows.py file in godot-cpp this is already included .. Is it a visual studio option? add the options to visual studio that you mention, but it still does not compile |
Logs? |
Build started at 10:52... |
try the project directly |
PROBLEM SOLUTIONTemplate project uploaded to gitlab. I uploaded it to Gitlab because the free Gitlab repositories support up to 10 GB and this is important because I upload the precompiled static libraries and all the godot-cpp. Even if it is possible, I will try to add a blender3D within the same repository... Just download the project and not have to do any type of configuration. https://gitlab.com/kone9/visual-studio-godot-engine-gdextension-cpp-template This proyect have 4 solutionsdebug mode and release mode. You can run the game directly from visual studio or open the godot editor.
Here are all the steps in a single Comment.To generate the visual studio compatible static libraries that are saved in godot-cpp/bin use the following scons command. lib debug:
lib release
Note that extension_api.json in godot-cpp 4.2 is located inside gdextension\extension_api.json. Pay attention to the location of "extension_api.json" Then in the project properties you have to add the following settingsGeneral
Debugging
VCC Directories
C/C++Preprocessor
Code GenerationLinkerGeneral
Input
Don't forget the "gdexample.gdextension" that goes inside the godot project and generates that link between gdextension and godot.Also very important to set the property [configuration] Visual Studio 2022 stable, Python, Scons, windows 11 |
Excuse me for asking you... |
Do you mean that you open If so, the debugger will not work because the Next, there may only be problems with flags that Visual Studio itself will report when you click on Hot-Reload (it seems). I don't remember my Visual Studio not being able to use Hot-Reload. The library and debugging symbols are always picked up on the fly, even with the new hot reload system in godot itself (4.2+). |
open the project directly in debug mode, use --editor. video showing that error |
In this video you can also see that hot reload does not work in editor mode, only in game mode, I have exactly the same configuration, only I start editor mode. |
As far as I understand, this is the correct behavior, because debugging is started for only one process - for the editor. A running project is a different process. You can attach to a running project manually via the But also keep in mind that Hot-reload does not change the library during debugging and the project being launched will also not change during restarts. In order for the changes to be applied to the project being launched, it is better to look towards hot-reload in godot 4.2 itself godotengine/godot#80284 [configuration]
entry_symbol = "example_init"
compatibility_minimum = "4.2"
reloadable = true You also need to add the |
Here they talk about the problem of GDextension and hot reloading, it seems that it does not work correctly when we enable it. |
Implement reloading of GDExtensions |
You know I was doing tests and If I do it on Windows with vscode, it tells me a permissions error with pdb. When I compile with VScode on Windows I do use Scons LAUNCH.JSON
TASKS.JSON
With Visual Studio it seems the same, there is a strange error there that does not allow the plugin to be reloaded in Windows. |
Can you read the last section of my previous message again? |
modify the previous comment. |
Again:
In your
Linux allows you to delete executable files after startup... |
I do not recommend doing this. I have a script made for my library with its own features and file structure. Here is a script from the documentation that I have modified so that it automatically renames the PDB: #!/usr/bin/env python
import os
import sys
from pathlib import Path
env = SConscript("../SConstruct")
bin_dir = "project/bin"
def is_file_locked(file_path):
if not os.path.exists(file_path):
return False
try:
with open(file_path, "a") as f:
pass
except IOError:
return True
return False
def msvc_pdb_rename(env, lib_full_name):
new_name = (Path(bin_dir) / lib_full_name).as_posix()
max_files = 256
# clean up the old PDBs if possible
onlyfiles = [
f
for f in os.listdir(Path(bin_dir))
if os.path.isfile(os.path.join(Path(bin_dir), f)) and f.endswith(".pdb") and f.startswith(lib_full_name)
]
# sort by time and leave only the newest PDB
onlyfiles = sorted(onlyfiles, key=lambda x: os.path.getmtime(os.path.join(bin_dir, x)))[:-1]
for of in onlyfiles:
try:
os.remove(Path(bin_dir) / of)
except:
pass
# search for a non-blocked PDB name
pdb_name = ""
for s in range(max_files):
pdb_name = "{}_{}.pdb".format(new_name, s)
if not is_file_locked(pdb_name):
break
# explicit assignment of the PDB name
env.Append(LINKFLAGS=["/PDB:" + pdb_name])
# For reference:
# - CCFLAGS are compilation flags shared between C and C++
# - CFLAGS are for C-specific compilation flags
# - CXXFLAGS are for C++-specific compilation flags
# - CPPFLAGS are for pre-processor flags
# - CPPDEFINES are for pre-processor defines
# - LINKFLAGS are for linking flags
# tweak this if you want to use different folders, or more folders, to store your source code in.
env.Append(CPPPATH=["src/"])
sources = Glob("src/*.cpp")
if env["platform"] == "macos":
library = env.SharedLibrary(
"{}/libgdexample.{}.{}.framework/libgdexample.{}.{}".format(
bin_dir, env["platform"], env["target"], env["platform"], env["target"]
),
source=sources,
)
else:
if env.get("is_msvc", False) and env["target"] != "template_release":
msvc_pdb_rename(env, "libgdexample{}".format(env["suffix"]))
library = env.SharedLibrary(
"{}/libgdexample{}{}".format(bin_dir, env["suffix"], env["SHLIBSUFFIX"]),
source=sources,
)
Default(library) And this still doesn't apply to I am not ready to help further, I have my own tasks. |
Okay, thank you very much. I was trying to do exactly the same thing. |
I will do it myself now, as I found a similar issue in godot repo. godotengine/godot#82536 |
Great, thank you very much for your time. I value it a lot. |
Now I only need Visual Studio. |
Hello, I just want to say that in visual studio after adding the following It does not work in debug mode, but at least it is not necessary to restart the editor, which is very important. Beyond this, what seems very strange to me is that if the game is run directly the hot reload works, but when it is run in editor mode it does not work. |
I am going to continue documenting Visual Studio errors here with the topic of debugging with hot reload. Now that the saving is working, you see that there is an error with the PDB file and it is not because there are no debugging symbols, it seems that it is looking for an .obj that it cannot find.
|
When you compile a program in Visual Studio, Program Database (PDB) files are generated that contain debugging information. These PDB files are useful for debugging code and detailed tracing during program execution. The linker searches for these PDB files to associate debugging information with the executable code. Setting PDB file search paths in Visual Studio allows you to specify the locations where the linker should search for the corresponding PDB files during program execution. Here is a step-by-step guide to verify and configure PDB file search paths in Visual Studio: Open your project in Visual Studio. From the menu, select "View" and then "Property Manager." This will open the Project Property Manager. In the Property Manager, you will find settings for various platforms and configurations (for example, Debug and Release). Select the specific configuration you are using (for example, "Debug"). Expand the selected settings and look for the "Microsoft.Cpp.x64.user" category (or "Microsoft.Cpp.Win32.user" for 32-bit platforms). Inside "Microsoft.Cpp.x64.user", look for the "Linker" section and expand "Debugging". In the "Debugging" section, you'll find a property called "AdditionalSymbolDirectories" (or similar). This is where you can specify search paths for additional PDB files. Make sure the paths specified here are correct and point to the directories where the PDB files needed for your project are located. Save changes to the project settings. This process may vary slightly depending on the specific version of Visual Studio you are using, but will generally follow a similar structure. The main idea is to adjust the settings related to the linker and search paths to ensure that the PDB files can be found during program execution. Remember that PDB file search paths are important for debugging, so it's critical to ensure they are set correctly to avoid linking issues during development. |
In the compiler options, there seems to be an option that allows you to forcibly rewrite the file called It is an option in the visual studio compiler, but I can't find the way around it. https://learn.microsoft.com/en-us/cpp/build/reference/fs-force-synchronous-pdb-writes?view=msvc-160 |
For now in Visual Studio I will open the editor with CTRL + F5 without a debugger, at least this way I can start the editor and although I can't debug, I will be able to compile and reload while the editor is running.IF I want to debug, for now I will have to confirm myself only in game mode.But hey, at least it works within visual studio without scons.. |
Godot version
4.2 stable
System information
windows 11, intel i5 10ma, rx 6600 xt,godot 4.2 stable
Issue description
Compile GDextension with Visual studio 2022, I can run godot, but it does not compile correctly, it seems that there is a problem and incompatibility with the .lib generated with the binding in godot-cpp
libgodot-cpp.windows.template_debug.x86_64.lib(error_macros.windows.template_debug.x86_64.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in register_types.obj
Steps to reproduce
in windows 11
install visual studio 2022 with libraries, python, scons and git.
Download this template project that is fully configured and press F5, you will see that it loads the game from godot, but it does not compile
https://gitlab.com/kone9/visual-studio-godot-engine-gdextension-cpp-template
try to generate the .lib in godot-cpp with different configurations,
For example, I already tried this one and it doesn't work.
scons platform=windows custom_api_file=gdextension\extension_api.json generate_bindings=yes
The issue is that Visual Studio does not need scons to generate the DLL, but to generate the .lib you have to use scons. I don't know what the error would be, but it seems that there is a problem with the .lib generated with scons in godot-cpp
Minimal reproduction project
I created this project where it is explained in detail how to configure Visual Studio with GDextension, but for some reason it doesn't work. I also want to clarify that I did this configuration previously with GDnative and it did work, although obviously the includes were different.
Please look at this project carefully because it contains all the configurations in visual studio 2022 in detail and it is an example of a downloadable template that should be able to be used anywhere.
Open the project with visual studio 2022 stable version
https://gitlab.com/kone9/visual-studio-godot-engine-gdextension-cpp-template
The text was updated successfully, but these errors were encountered: