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

Unable to build for windows #120

Closed
phileagleson opened this issue Aug 25, 2023 · 6 comments
Closed

Unable to build for windows #120

phileagleson opened this issue Aug 25, 2023 · 6 comments

Comments

@phileagleson
Copy link

When I try to build this library with windows as a target I'm getting several errors in iter.go:

➜ GOARCH=amd64 GOOS=windows go build .
 github.com/smacker/go-tree-sitter
./iter.go:17:18: undefined: Node
./iter.go:21:21: undefined: Node
./iter.go:25:20: undefined: Node
./iter.go:30:26: undefined: Node
./iter.go:34:20: undefined: Node
./iter.go:38:32: undefined: Node
./iter.go:43:9: undefined: Node
./iter.go:46:18: undefined: Node
./iter.go:68:40: undefined: Node

When building for linux, the build succeeds as expected. I can see 'Node' is defined in bindings.go and both iter.go and bindings.go are part of the sitter package so I''m not sure why this error occurs.

@phileagleson
Copy link
Author

In case this helps anyone else - I was able to fix this by installing a cross-compile version of gcc. I'm using Arch, but the package names should be similar on other distros:
install :

  • gcc-multilib
  • mingw-w64-gcc

set additional flags when building:

	GOARCH=amd64 GOOS=windows \
           CGO_ENABLED=1 \
           CXX=x86_64-w64-mingw32-g++ \
           CC=x86_64-w64-mingw32-gcc \
	   go build -o bin/appName64.exe cmd/app/main.go 

@phileagleson
Copy link
Author

After further testing, the previous method, still had issues. The app would compile fine, but when running on a Windows machine, it was missing some required dll's for the c standard library. The easiest way I found to get around this was surprisingly to use zig to compile.

https://dev.to/kristoff/zig-makes-go-cross-compilation-just-work-29ho

Using this method, I get a static binary that works on Windows and doesn't require any additional dependencies

@zimmski
Copy link

zimmski commented Sep 6, 2023

Sorry i overlooked this thread even though we can add our experience to it. (Vacation are bad for your mail queue!)

We are building https://symflower.com for Linux/MacOS/Windows for different architectures. For Windows we are using https://github.com/mstorsjo/llvm-mingw which works great! I had multiple looks into Zig (did not look into the latest 0.11 release though!) and i had smaller compilation problems that were solvable but the binaries crashed in various scenarios. I tracked down most of them in open issues, don't know their current state, i just wanted to note: if your binary crashes, might be because of compiling with Zig, so please let them know.

One option that we are using is -tags=netgo,osusergo.

Your original problem #120 (comment) i can explain. AFAIK if you are cross compiling, CGO is disabled, so you need to explicitly enable it with CGO_ENABLED=1 and that you did :-)

@Owatron
Copy link

Owatron commented Feb 12, 2024

I have the same issue , can you please help me out?

@Borwe
Copy link

Borwe commented Feb 27, 2024

Whats the solution for those on Windows?

@zimmski
Copy link

zimmski commented Apr 30, 2024

I have the same issue , can you please help me out?

@Owatron @Borwe i guess https://www.mingw-w64.org/ is a compiler for Windows? Please let me know if it worked.

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

No branches or pull requests

4 participants