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

Build failing when building on windows 11 #151

Closed
allain opened this issue Mar 7, 2024 · 5 comments
Closed

Build failing when building on windows 11 #151

allain opened this issue Mar 7, 2024 · 5 comments

Comments

@allain
Copy link

allain commented Mar 7, 2024

This is the error message I'm seeing.

$ go build
# example/hello
C:\Program Files\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/allai/go/pkg/mod/github.com/buke/quickjs-go@v0.4.1/deps/libs/windows_amd64/libquickjs.a(quickjs.nolto.o): in function `js_atomics_wait':
D:\a\quickjs-go\quickjs-go\deps\quickjs/quickjs.c:55522: undefined reference to `clock_gettime'
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/allai/go/pkg/mod/github.com/buke/quickjs-go@v0.4.1/deps/libs/windows_amd64/libquickjs.a(quickjs-libc.nolto.o): in function `js_std_getenviron':
D:\a\quickjs-go\quickjs-go\deps\quickjs/quickjs-libc.c:703: undefined reference to `__imp___p__environ'
collect2.exe: error: ld returned 1 exit status

If it helps I'm using mingw and this is the info I get from gcc:

$ gcc -v
Using built-in specs.
COLLECT_GCC=C:\TDM-GCC-64\bin\gcc.exe
COLLECT_LTO_WRAPPER=C:/TDM-GCC-64/bin/../libexec/gcc/x86_64-w64-mingw32/10.3.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-git-10.3.0/configure --build=x86_64-w64-mingw32 --enable-targets=all --enable-languages=ada,c,c++,fortran,jit,lto,objc,obj-c++ --enable-libgomp --enable-lto --enable-graphite --enable-cxx-flags=-DWINPTHREAD_STATIC --disable-build-with-cxx --disable-build-poststage1-with-cxx --enable-libstdcxx-debug --enable-threads=posix --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts=yes --disable-libstdcxx-pch --enable-libstdcxx-threads --enable-libstdcxx-time=yes --enable-mingw-wildcard --with-gnu-ld --disable-werror --enable-nls --disable-win32-registry --enable-large-address-aware --disable-rpath --disable-symvers --prefix=/mingw64tdm --with-local-prefix=/mingw64tdm --with-pkgversion=tdm64-1 --with-bugurl=https://github.com/jmeubank/tdm-gcc/issues
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.3.0 (tdm64-1)

Let me know if I can help with anything.

@allain allain changed the title Build failing when building on windows 11 amd64 Build failing when building on windows 11 Mar 7, 2024
@buke
Copy link
Owner

buke commented May 20, 2024

The windows static library is compiled based on mingw 12.2.0. Please confirm that your go version > 1.20.0

@dvwzj
Copy link

dvwzj commented May 27, 2024

Same here but a little bit difference.

$ gcc -v
Using built-in specs.
COLLECT_GCC=C:\msys64\mingw64\bin\gcc.exe
COLLECT_LTO_WRAPPER=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-13.2.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/include --libexecdir=/mingw64/lib --enable-bootstrap --enable-checking=release --with-arch=nocona --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++,jit --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts --enable-libstdcxx-time --disable-libstdcxx-pch --enable-lto --enable-libgomp --disable-libssp --disable-multilib --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev2, Built by MSYS2 project' --with-bugurl=https://github.com/msys2/MINGW-packages/issues --with-gnu-as --with-gnu-ld --disable-libstdcxx-debug --with-boot-ldflags=-static-libstdc++ --with-stage1-ldflags=-static-libstdc++
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.0 (Rev2, Built by MSYS2 project)
$  go version
go version go1.22.2 windows/amd64
// main.go
package main

import (
	"fmt"

	"github.com/buke/quickjs-go"
)

func main() {
	// Create a new runtime
	rt := quickjs.NewRuntime()
	defer rt.Close()
	// Create a new context
	ctx := rt.NewContext()
	defer ctx.Close()

	jsStr := `
    function fib(n)
    {
        if (n <= 0)
            return 0;
        else if (n == 1)
            return 1;
        else
            return fib(n - 1) + fib(n - 2);
    }
    fib(10)
    `
	// Compile the script to bytecode
	buf, _ := ctx.Compile(jsStr)

	// Create a new runtime
	rt2 := quickjs.NewRuntime()
	defer rt2.Close()

	// Create a new context
	ctx2 := rt2.NewContext()
	defer ctx2.Close()

	//Eval bytecode
	result, _ := ctx2.EvalBytecode(buf)
	fmt.Println(result.Int32())
}
$ go run .
C:\Program Files\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/dvwzj/go/pkg/mod/github.com/buke/quickjs-go@v0.4.6/deps/libs/windows_amd64/libquickjs.a(quickjs-libc.nolto.o): in function `js_std_getenviron':
D:/a/quickjs-go/quickjs-go/deps/quickjs/quickjs-libc.c:703:(.text+0x2d2e): undefined reference to `__imp___p__environ'
collect2.exe: error: ld returned 1 exit status
// My device info
Processor	AMD Ryzen 5 5500                                  3.60 GHz
System type	64-bit operating system, x64-based processor
// My windows info
Edition	Windows 11 Pro
Version	24H2
Installed on	‎2024-‎04-‎04
OS build	26120.670
Experience	Windows Feature Experience Pack 1000.26100.6.0

@buke
Copy link
Owner

buke commented May 28, 2024

I just build it successfully, here is my steps:

1. download and install msys2 from https://www.msys2.org
2. install gcc

$ pacman -S mingw-w64-ucrt-x86_64-gcc
resolving dependencies...
looking for conflicting packages...

Packages (16) mingw-w64-ucrt-x86_64-binutils-2.42-2  mingw-w64-ucrt-x86_64-crt-git-11.0.0.r731.g8fdf7c9b5-1  mingw-w64-ucrt-x86_64-gcc-libs-13.2.0-6
              mingw-w64-ucrt-x86_64-gettext-runtime-0.22.5-2  mingw-w64-ucrt-x86_64-gmp-6.3.0-2
              mingw-w64-ucrt-x86_64-headers-git-11.0.0.r731.g8fdf7c9b5-1  mingw-w64-ucrt-x86_64-isl-0.26-1  mingw-w64-ucrt-x86_64-libiconv-1.17-4
              mingw-w64-ucrt-x86_64-libwinpthread-git-11.0.0.r731.g8fdf7c9b5-1  mingw-w64-ucrt-x86_64-mpc-1.3.1-2
              mingw-w64-ucrt-x86_64-mpfr-4.2.1-2  mingw-w64-ucrt-x86_64-windows-default-manifest-6.4-4
              mingw-w64-ucrt-x86_64-winpthreads-git-11.0.0.r731.g8fdf7c9b5-1  mingw-w64-ucrt-x86_64-zlib-1.3.1-1  mingw-w64-ucrt-x86_64-zstd-1.5.6-2
              mingw-w64-ucrt-x86_64-gcc-13.2.0-6

Total Download Size:     3.96 MiB
Total Installed Size:  479.40 MiB

:: Proceed with installation? [Y/n] y


3. add "C:\msys64\ucrt64\bin" to Environment Variables

4. set CGO in the 
> go env CGO_ENABLED=1 

5. clone the project
> git clone https://github.com/buke/quickjs-go.git

5. build the project
> cd  quickjs-go
> go mod tidy
> go build -v ./...
runtime/cgo
github.com/buke/quickjs-go

and the info

PS C:\Users\wangb> go version
go version go1.22.3 windows/amd64
PS C:\Users\wangb> go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\wangb\AppData\Local\go-build
set GOENV=C:\Users\wangb\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\wangb\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\wangb\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.22.3
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\wangb\AppData\Local\Temp\go-build490567261=/tmp/go-build -gno-record-gcc-switches
$ gcc -v
Using built-in specs.
COLLECT_GCC=C:\msys64\ucrt64\bin\gcc.exe
COLLECT_LTO_WRAPPER=C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-13.2.0/configure --prefix=/ucrt64 --with-local-prefix=/ucrt64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/ucrt64/include --libexecdir=/ucrt64/lib --enable-bootstrap --enable-checking=release --with-arch=nocona --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++,jit --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts --enable-libstdcxx-time --disable-libstdcxx-pch --enable-lto --enable-libgomp --disable-libssp --disable-multilib --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/ucrt64 --with-mpfr=/ucrt64 --with-mpc=/ucrt64 --with-isl=/ucrt64 --with-pkgversion='Rev6, Built by MSYS2 project' --with-bugurl=https://github.com/msys2/MINGW-packages/issues --with-gnu-as --with-gnu-ld --disable-libstdcxx-debug --enable-plugin --with-boot-ldflags=-static-libstdc++ --with-stage1-ldflags=-static-libstdc++
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.0 (Rev6, Built by MSYS2 project)

Device specifications
Device name	DESKTOP-V6G85P5
Processor	Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz   2.21 GHz
Installed RAM	8.00 GB
Device ID	927CDC99-90A4-4448-9A3F-E305454A07A9
Product ID	00330-80000-00000-AA460
System type	64-bit operating system, x64-based processor
Pen and touch	No pen or touch input is available for this display
Windows specifications
Edition	Windows 11 Pro
Version	23H2
Installed on	‎5/‎28/‎2024
OS build	22631.2861
Experience	Windows Feature Experience Pack 1000.22681.1000.0

@buke buke mentioned this issue May 28, 2024
@dvwzj
Copy link

dvwzj commented May 29, 2024

I can confirm that if we use ucrt64 we will build successfully

@buke
Copy link
Owner

buke commented May 29, 2024

thank you for your confirm , I going to close this issue. if have any question, please reopen it

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

3 participants