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 assumes mingw, causes failures with clang for windows #16932

Closed
nadiasvertex opened this issue Aug 30, 2016 · 4 comments
Closed

build: cgo assumes mingw, causes failures with clang for windows #16932

nadiasvertex opened this issue Aug 30, 2016 · 4 comments

Comments

@nadiasvertex
Copy link
Contributor

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

go version go1.7 windows/amd64

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

Windows Server 2012 R2 / AMD64

What did you do?

I used CGO with Clang for Windows 3.8.1 (http://llvm.org/releases/3.8.1/LLVM-3.8.1-win64.exe) like this:

set CC=clang
set CGO_CFLAGS="-m64 -Ipath/to/my/includes"
set CGO_LDFLAGS = "-v -Xlinker -libpath:path/to/libs -lwldap32 -ladvapi32 -lws2_32 -ldbghelp -luser32"

go build

What did you expect to see?

Expected to see nothing (ie, successful compile)

What did you see instead?

clang version 3.8.1 (branches/release_38)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: D:\llvm\bin
 "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin\\amd64\\link.exe" "-out:C:\\Users\\USAWTB~1\\AppData\\Local\\Temp\\2\\go-build808013706\\editor
\\dom\\_obj\\_all.o" "-libpath:C:\\Program Files (x86)\\Microsoft Visual Studio
14.0\\VC\\lib\\amd64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\
10.0.10586.0\\ucrt\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Li
b\\10.0.10586.0\\um\\x64" -nologo "C:\\Users\\USAWTB~1\\AppData\\Local\\Temp\\2\
\go-build808013706\\editor\\dom\\_obj\\_cgo_export.o" "C:\\Users\\USAWTB~1\\AppD
ata\\Local\\Temp\\2\\go-build808013706\\editor\\dom\\_obj\\binding.cgo2.o" -Xlin
ker -r --start-group mingwex.lib mingw32.lib --end-group
LINK : warning LNK4044: unrecognized option '/Xlinker'; ignored
LINK : warning LNK4044: unrecognized option '/r'; ignored
LINK : warning LNK4044: unrecognized option '/-start-group'; ignored
LINK : warning LNK4044: unrecognized option '/-end-group'; ignored
LINK : fatal error LNK1181: cannot open input file 'mingwex.lib'
clang.exe: error: linker command failed with exit code 1181 (use -v to see invocation)

I believe the basic problem is the -Xlinker -r --start-group mingwex.lib mingw32.lib --end-group at the end. This is added in cmd/go/build.go, line 3427.

Perhaps the go build command could check the version of the compiler, since:

$ clang -v
clang version 3.8.1 (branches/release_38)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: D:\llvm\bin

The "msvc" tag would be a good indication not to use mingw.

@bradfitz bradfitz changed the title cgo assumes mingw, causes failures with clang for windows build: cgo assumes mingw, causes failures with clang for windows Aug 30, 2016
@ianlancetaylor ianlancetaylor added this to the Go1.8 milestone Aug 30, 2016
@alexbrainman
Copy link
Member

I just removed (https://go-review.googlesource.com/#/c/26670/) line 3427 from cmd/go/build.go.

Alex

@nadiasvertex
Copy link
Contributor Author

I can verify that this fix resolves this error for me.

@luna-duclos
Copy link

luna-duclos commented Oct 11, 2016

I have another error using clang for windows: cgo tries to add -lm to the linker flags, which with gcc, includes the math library, however, this library doesn't exist on clang for windows, and the flag shouldn't be there.

Perhaps this should be reopened and fixed under the same issue ? Or should I log a seperate issue ?

@alexbrainman
Copy link
Member

cgo tries to add -lm to the linker flags, which with gcc, includes the math library, however, this library doesn't exist on clang for windows, and the flag shouldn't be there.

http://golang.org/cl/31791 to remove -lm flag.

Alex

@golang golang locked and limited conversation to collaborators Oct 24, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants