Go version
go version go1.24.4 windows/amd64
Output of go env
in your module/workspace:
set AR=ar
set CC=gcc
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_ENABLED=1
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set CXX=g++
set GCCGO=gccgo
set GO111MODULE=
set GOAMD64=v1
set GOARCH=amd64
set GOAUTH=netrc
set GOBIN=
set GOCACHE=C:\Users\hajimehoshi\AppData\Local\go-build
set GOCACHEPROG=
set GODEBUG=
set GOENV=C:\Users\hajimehoshi\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFIPS140=off
set GOFLAGS=
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\HAJIME~1\AppData\Local\Temp\go-build655081393=/tmp/go-build -gno-record-gcc-switches
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMOD=C:\Users\hajimehoshi\test\test\go.mod
set GOMODCACHE=C:\Users\hajimehoshi\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\hajimehoshi\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\hajimehoshi\AppData\Roaming\go\telemetry
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.24.4
set GOWORK=
set PKG_CONFIG=pkg-config
What did you do?
- Compile this
main.go
withgo build -buildmode=c-archive main.go
and createmain.a
package main
import "C"
//export PrintSum
func PrintSum(a C.int, b C.int) {
println(a + b)
}
func main() {
}
- Prepare this
main.c
int PrintSum(int a, int b);
int main() {
PrintSum(1, 2);
}
- Open a terminal for Visual Studio tools (e.g. x64 Native Tools Command Prompt for VS 2022)
- Run this
cl main.c main.a msvcrt.lib
What did you see happen?
Microsoft(R) C/C++ Optimizing Compiler Version 19.38.33139 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
cl : コマンド ライン warning D9024 : ソースファイルの種類 'main.a' は認識できませんでした。オブジェクト ファイルと仮定します。
main.c
Microsoft (R) Incremental Linker Version 14.38.33139.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:main.exe
main.obj
main.a
msvcrt.lib
LINK : warning LNK4098: defaultlib 'LIBCMT' は他のライブラリの使用と競合しています。/NODEFAULTLIB:library を使用してください。
main.a(000005.o) : error LNK2019: 未解決の外部シンボル __mingw_vfprintf が関数 fprintf で参照されました
main.a(000007.o) : error LNK2001: 外部シンボル __mingw_vfprintf は未解決です
main.exe : fatal error LNK1120: 1 件の未解決の外部参照
I'm afraid the message was translated into Japanese, but this says that the symbol __mingw_vprintf
could not be resolved.
What did you expect to see?
The compilation succeeds.
Comment From: gabyhelp
Related Issues
- cmd/go: compilation with msvc compiler fails #36283 (closed)
- cmd/cgo: aborts on attempt to link to static library on windows #44308 (closed)
- cmd/link: Windows errors with internal linking with C objects #23268 (closed)
- cmd/link: cross compile from MacOS to Windows with CGO_ENABLED=1 and -buildmode=c-archive not working #59221 (closed)
- cmd/link: cgo linking fails on Windows with GCC 11.2.0 + MinGW-w64 9.0.0 (UCRT) from winlibs.com #51007 (closed)
- cmd/link: clang on windows fatal error LNK1104: cannot open file 'mingwex.lib' #60202 (closed)
- cmd/link: undefined reference to __imp___iob_func on windows with import C / x/sys/windows #57455 (closed)
- Build: Can't import static lib on window 10 #61803 (closed)
- build: cgo with clang and -buildmode=c-shared failures on Windows #42146 (closed)
Related Discussions
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: cherrymui
Unfortunately we don't support linking with MSVC. You may follow #20982 for MSVC support. Thanks.
Comment From: hajimehoshi
This is an issue about linking an output C archive with MSVC, and not using MSVC as CC to compile a C archive. Is this issue included in #20982?
Comment From: cherrymui
This is an issue about linking an output C archive with MSVC
Yeah, which is not supported either. I think we can use a single issue to track MSVC support. Thanks.