cmd/link: Windows errors with internal linking with C objects #23268
Comments
Does external linking mode work for you? |
That error doesn't make any sense. Can anybody recreate it? I haven't been able to, but I'm not using WIndows. We don't promise that internal linking mode works for anything other than Go code. It's nice when it works with arbitrary C code, but there are no guarantees. Still, I don't see why or how it would fail in this way. |
On tip and go1.8, I can see
|
Okay, |
Note: we are using msys2 I have also modify the git repository (https://github.com/tahirhassan10p/GoLangInternalFlag.git) and added a dockerfile.win file to make it easy to replicate the error. |
Why do you want to use internal linking mode? |
I can confirm this works with external linker, but does not work with internal linker. I think the problem is the ldflag I will try and fix this when I have some time. I have very little free time now days, so hopefully someone will beat me to it. Alex |
If |
Good point about @tahirhassan10p Unless there is a good reason that we need to support internal linking here, I'm inclined to close this issue. |
@hirochachacha and @ianlancetaylor you are correct about I agree, it would be too hard to parse
But maybe I am overthinking this too much. Perhaps we could just document that this is not supported with internal linker. Leaving it for @ianlancetaylor to decide what to do here. Alex |
Timed out in state WaitingForInfo. Closing. (I am just a bot, though. Please speak up if this is a mistake or you have the requested information.) |
What version of Go are you using (
go version
)?go version go1.9.2 windows/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?GOARCH=amd64
GOBIN=
GOEXE=.exe
GOHOSTARCH=amd64
GOHOSTOS=windows
GOOS=windows
GOPATH=C:\gopath
GORACE=
GOROOT=C:\go
GOTOOLDIR=C:\go\pkg\tool\windows_amd64
GCCGO=gccgo
CC=C:/scripts/fips.bat
GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\ContainerAdministrator\AppData\Local\Temp\go-build167486487=/tmp/go-build -gno-record-gcc-switches
CXX=g++
CGO_ENABLED=1
CGO_CFLAGS=-g -O2
CGO_CPPFLAGS=
CGO_CXXFLAGS=-g -O2
CGO_FFLAGS=-g -O2
CGO_LDFLAGS=-g -O2
PKG_CONFIG=pkg-config
What did you do?
I want to run golang code which is importing C archive code with -ldflags "-linkmode=internal" flag.
addition.c
int addition(int a,int b) { int result; result = a + b; return result; }
multiplication.c
int multiplication(int a, int b) { int result; result = a * b; return result; }
header.h
#include <stdio.h> int addition(int a,int b); int multiplication(int a,int b);
program.go
`package main
/*
#include <stdio.h>
#include <stdlib.h>
#include "header.h"
#cgo CFLAGS: -I./
#cgo LDFLAGS: ./libarith.a
void myprint() {
int result;
result = addition(1,2);
printf("addition result is : %d\n",result);
result = multiplication(3,2);
printf("multiplication result is : %d\n",result);
}
*/
import "C"
import "fmt"
func main() {
fmt.Println("Hello world from archive")
C.myprint()
}`
Codebase is also available on (https://github.com/tahirhassan10p/GoLangInternalFlag.git).
Steps to reproduce
What did you expect to see?
Hello world from archive
addition result is : 3
multiplication result is : 6
What did you see instead?
C:\go\pkg\tool\windows_amd64\link.exe: cannot open file "-m64 --print-libgcc-file-name"
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/libgcc.a: open "-m64 --print-libgcc-file-name"
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/libgcc.a: The filename, directory name, or volume label syntax is incorrect.
The text was updated successfully, but these errors were encountered: