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: cgo with clang and -buildmode=c-shared failures on Windows #42146

Open
tungmangtdh3 opened this issue Oct 22, 2020 · 4 comments
Open

build: cgo with clang and -buildmode=c-shared failures on Windows #42146

tungmangtdh3 opened this issue Oct 22, 2020 · 4 comments

Comments

@tungmangtdh3
Copy link

@tungmangtdh3 tungmangtdh3 commented Oct 22, 2020

What version of Go are you using (go version)?

$ go version
go version go1.15.3 windows/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\nguyenha\AppData\Local\go-build
set GOENV=C:\Users\nguyenha\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\nguyenha\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\nguyenha\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=D:\work\projects\mimic\mimic-core\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\nguyenha\AppData\Local\Temp\go-build611343782=/tmp/go-build -gno-record-gcc-switches

What did you do?

set CGO_ENABLED=1
set CC=clang
set PATH=C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin;%PATH%
go build -buildmode=c-shared -o bin/crawler.dll -ldflags "-v" -v my/pathp/export

What did you expect to see?

Build success.

What did you see instead?

HEADER = -H10 -T0xffffffffffffffff -R0xffffffff
pclntab=1272164 bytes, funcdata total 320301 bytes
symsize = 0
host link: "clang" "-m64" "-mconsole" "-Wl,--tsaware" "-Wl,--nxcompat" "-Wl,--major-os-version=6" "-Wl,--minor-os-version=1" "-Wl,--major-subsystem-version=6" "-Wl,--minor-subsystem-version=1" "-Wl,-Bsymbolic" "-shared" "-o" "crawler.dll" "-Qunused-arguments" "C:\Users\nguyenha\AppData\Local\Temp\go-link-077327015\go.o" "C:\Users\nguyenha\AppData\Local\Temp\go-link-077327015\000000.o" "C:\Users\nguyenha\AppData\Local\Temp\go-link-077327015\000001.o" "C:\Users\nguyenha\AppData\Local\Temp\go-link-077327015\000002.o" "C:\Users\nguyenha\AppData\Local\Temp\go-link-077327015\000003.o" "C:\Users\nguyenha\AppData\Local\Temp\go-link-077327015\000004.o" "C:\Users\nguyenha\AppData\Local\Temp\go-link-077327015\000005.o" "C:\Users\nguyenha\AppData\Local\Temp\go-link-077327015\000006.o" "C:\Users\nguyenha\AppData\Local\Temp\go-link-077327015\000007.o" "C:\Users\nguyenha\AppData\Local\Temp\go-link-077327015\000008.o" "-g" "-O2" "-g" "-O2" "-Wl,-T,C:\Users\nguyenha\AppData\Local\Temp\go-link-077327015\fix_debug_gdb_scripts.ld" "-Wl,--start-group" "-lmingwex" "-lmingw32" "-Wl,--end-group" "-lkernel32"
c:\go\pkg\tool\windows_amd64\link.exe: running clang failed: exit status 1104
LINK : warning LNK4044: unrecognized option '/-tsaware'; ignored
LINK : warning LNK4044: unrecognized option '/-nxcompat'; ignored
LINK : warning LNK4044: unrecognized option '/-major-os-version=6'; ignored
LINK : warning LNK4044: unrecognized option '/-minor-os-version=1'; ignored
LINK : warning LNK4044: unrecognized option '/-major-subsystem-version=6'; ignored
LINK : warning LNK4044: unrecognized option '/-minor-subsystem-version=1'; ignored
LINK : warning LNK4044: unrecognized option '/Bsymbolic'; ignored
LINK : warning LNK4044: unrecognized option '/T'; ignored
LINK : warning LNK4044: unrecognized option '/-start-group'; ignored
LINK : warning LNK4044: unrecognized option '/-end-group'; ignored
LINK : fatal error LNK1104: cannot open file 'mingwex.lib'
clang: error: linker command failed with exit code 1104 (use -v to see invocation)

@tungmangtdh3
Copy link
Author

@tungmangtdh3 tungmangtdh3 commented Oct 22, 2020

I see the error LINK : fatal error LNK1104: cannot open file 'mingwex.lib'
looks like #16932

@dmitshur
Copy link
Member

@dmitshur dmitshur commented Oct 28, 2020

What version of clang is it?

In go env output it says CC=gcc—is that because you ran go env before setting those env vars as shown in "what did you do" section?

CC @ianlancetaylor, @alexbrainman.

@dmitshur dmitshur changed the title build: cgo with clang failures for windows build: cgo with clang and -buildmode=c-shared failures on Windows Oct 28, 2020
@dmitshur dmitshur added this to the Backlog milestone Oct 28, 2020
@tungmangtdh3
Copy link
Author

@tungmangtdh3 tungmangtdh3 commented Oct 29, 2020

What version of clang is it?

In go env output it says CC=gcc—is that because you ran go env before setting those env vars as shown in "what did you do" section?

CC @ianlancetaylor, @alexbrainman.

Yes, CC=gcc because I ran it before setting CC to clang in the batch.
Run it inside will shows:

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\nguyenha\AppData\Local\go-build
set GOENV=C:\Users\nguyenha\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\nguyenha\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\nguyenha\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=clang
set CXX=clang++
set CGO_ENABLED=1
set GOMOD=D:\work\projects\mimic\mimic-core\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\nguyenha\AppData\Local\Temp\go-build169138794=/tmp/go-build -gno-record-gcc-switches

clang --version shows:
clang version 11.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin

@alexbrainman
Copy link
Member

@alexbrainman alexbrainman commented Oct 31, 2020

@tungmangtdh3 you did not explain what you are trying to build. But, if you want to use clang to build Cgo program, you cannot. There is no support for this functionality. #17014 is about clang support building.

Alex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants