gd run example pong on Windows gives a error
ShirenY opened this issue · 13 comments
AT. log here:
D:\Workspace2\testGrow\eg-master>cd 2d/pong
D:\Workspace2\testGrow\eg-master\2d\pong>gd run
go: downloading grow.graphics/gd v0.0.0-20240512032421-6cab2dce2af5
go: downloading grow.graphics/xy v0.0.0-20240129002912-5a525950a952
go: downloading golang.org/x/text v0.15.0
go: downloading runtime.link v0.0.0-20240510041921-494aa7fd7f63
go: downloading grow.graphics/uc v0.0.0-20240128001120-57fde712a2f4
-buildmode=c-shared requires external (cgo) linking, but cgo is not enabled
exit status 1
D:\Workspace2\testGrow\eg-master\2d\pong>gd run
-buildmode=c-shared requires external (cgo) linking, but cgo is not enabled
exit status 1
D:\Workspace2\testGrow\eg-master\2d\pong>go version
go version go1.22.3 windows/amd64
Thanks for the report, can you try CGO_ENABLED=1 gd run
to see if this helps?
That was fast reply. I'm pretty new to golang. CGO_ENABLED=1 gd run in command line gives me a error says "CGO_ENABLED" is not a command.
oh, of course, sorry you are on Windows, you will need to set CGO_ENABLED=1
as an environment variable, a quick web search suggests, that you can set CGO_ENABLED=1
and then on the next command gd run
. If this fixes the issue, I should be able to update the gd
command to do this automatically.
Looks like cgo or gd depends on gcc. We don't usually install gcc on windows, since most game developer use msvc.
D:\Workspace2\testGrow\eg-master\2d\pong>set CGO_ENABLED=1
D:\Workspace2\testGrow\eg-master\2d\pong>gd run
# runtime/cgo
cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in %PATH%
exit status 1
Not sure whether MinGW's gcc will work. I will try it later.
I see, yes you can configure Go to use a different C compiler by using the CC
and CCX
environment variables but I am not sure that Go supports MSVC (see golang/go#20982). You will most likely have better luck using GCC, Clang, or Zig as the C compiler (all are Open Source options). If you can get something working, do let me know, as it would be helpful to document or help to automate the steps needed to successfully build on windows.
Okay, finally got it to work on Windows. There are some weird things to overcome, but yeah, I will record it here for anyone who comes later.
The gcc thing on Windows always looks weird. First, I tried to install MinGW, but CGO complains it's not a 64-bit compiler. There are too many options in MinGW, and I can't figure out if there's a compatible 64-bit version in it in a short time.
So I switched to TDM-GCC. Downloaded the 64-bit version, and finally, cgo works. It tried to run Godot to open the project, but it fails with the log below,
D:\Workspace2\testGrow\eg-master\2d\pong>gd run
Godot Engine v4.2.2.stable.official.15073afe3 - https://godotengine.org
Vulkan API 1.3.224 - Forward+ - Using Vulkan Device #0: NVIDIA - NVIDIA GeForce RTX 2060
ERROR: Unable to open file: res://.godot/imported/ball.png-9a4ca347acb7532f6ae347744a6b04f7.ctex.
at: (scene/resources/compressed_texture.cpp:41)
ERROR: Failed loading resource: res://.godot/imported/ball.png-9a4ca347acb7532f6ae347744a6b04f7.ctex. Make sure resources have been imported by opening the project in the editor at least once.
at: (core/io/resource_loader.cpp:274)
ERROR: Failed loading resource: res://ball.png. Make sure resources have been imported by opening the project in the editor at least once.
at: (core/io/resource_loader.cpp:274)
ERROR: Unable to open file: res://.godot/imported/paddle.png-0e798fb0912613386507c9904d5cc01a.ctex.
at: (scene/resources/compressed_texture.cpp:41)
ERROR: Failed loading resource: res://.godot/imported/paddle.png-0e798fb0912613386507c9904d5cc01a.ctex. Make sure resources have been imported by opening the project in the editor at least once.
at: (core/io/resource_loader.cpp:274)
ERROR: Failed loading resource: res://paddle.png. Make sure resources have been imported by opening the project in the editor at least once.
at: (core/io/resource_loader.cpp:274)
ERROR: res://main.tscn:45 - Parse Error: [ext_resource] referenced non-existent resource at: res://ball.png
at: _parse_ext_resource (scene/resources/resource_format_text.cpp:163)
ERROR: res://main.tscn:56 - Parse Error: [ext_resource] referenced non-existent resource at: res://paddle.png
at: _parse_ext_resource (scene/resources/resource_format_text.cpp:163)
ERROR: res://main.tscn:67 - Parse Error: [ext_resource] referenced non-existent resource at: res://paddle.png
at: _parse_ext_resource (scene/resources/resource_format_text.cpp:163)
exit status 0xc0000005
I suspect it's because projects need to be opened once before running them since the engine needs to import everything like Unity. So I manually opened the project with the engine. And boom, it works. I closed the engine, tried gd run, and it also works without errors.
Oh I fogot to mention need set CGO_ENABLED=1 of course.
I've added a change to the gd
command to set CGO_ENABLED=1
by default and to automatically import the godot project without having to open Godot. You can update the gd
command by running go get grow.graphics/gd/cmd/gd@master
. Let me know if this improves your experience and if you have any further ideas on how the experience can be improved for Windows users. I've updated the readme with a hint about setting up CGO. Also you, haven't mentioned how you installed Godot, do you think it would be helpful for the gd
command to download Godot automatically?
Again thank you very much for reporting your experience here, if you find that the project continues to meet your needs, please consider financially supporting us, even a small amount helps!
I tried go get grow.graphics/gd/cmd/gd@master
Afterward, I deleted the .godot folder for testing purposes. However, I continue to encounter the same engine errors when running GD.
Apart from this issue, everything seems to be functioning as anticipated. While I have some minor suggestions for life quality improvements from a game development perspective, I might submit them at a later time.
I'm definitely willing to offer financial support if my game launches successfully with your excellent plugin! 😄
Also you, haven't mentioned how you installed Godot, do you think it would be helpful for the
gd
command to download Godot automatically?
I don't require such assistance personally, as the error log provides me with the necessary information. However, I do have a preference regarding GD: I would appreciate the ability to specify the path where Godot is stored on my PC. I believe many users visiting this repository already have Godot installed elsewhere, for valid reasons.
I would appreciate the ability to specify the path where Godot is stored on my PC
Thanks, do you think an environment variable would be suitable for this?
I would appreciate the ability to specify the path where Godot is stored on my PC
Thanks, do you think an environment variable would be suitable for this?
I'm not sure. Since the go project need specific version of godot. Maybe take a parameter for advance usage or read from local config file will do.