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

cmd/link: Mac os x go use mingw32 build windows dll failed #26225

Closed
xs23933 opened this issue Jul 5, 2018 · 3 comments
Closed

cmd/link: Mac os x go use mingw32 build windows dll failed #26225

xs23933 opened this issue Jul 5, 2018 · 3 comments

Comments

@xs23933
Copy link

@xs23933 xs23933 commented Jul 5, 2018

Please answer these questions before submitting your issue. Thanks!

MacOS version

macos High Sierra 10.13.5 (17F77)

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

go version go1.10.3 darwin/amd64

mingw32 version

i686-w64-mingw32-gcc -v
COLLECT_GCC=i686-w64-mingw32-gcc
COLLECT_LTO_WRAPPER=/usr/local/Cellar/mingw-w64/5.0.4/toolchain-i686/libexec/gcc/i686-w64-mingw32/8.1.0/lto-wrapper
:i686-w64-mingw32
:../configure --target=i686-w64-mingw32 --prefix=/usr/local/Cellar/mingw-w64/5.0.4/toolchain-i686 --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --enable-languages=c,c++,fortran--with-ld=/usr/local/Cellar/mingw-w64/5.0.4/toolchain-i686/bin/i686-w64-mingw32-ld --with-as=/usr/local/Cellar/mingw-w64/5.0.4/toolchain-i686/bin/i686-w64-mingw32-as --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --disable-multilib --enable-threads=win32

my code

`package main

import (
"C"
"fmt"
)
//export Hello
func Hello() {
fmt.Printf("Hello Im golang\n")
}

func main() {}`

build information

`CGO_ENABLED=1 CC=i686-w64-mingw32-gcc GOOS=windows GOARCH=386 go build -ldflags "-s -w" -x -buildmode=c-shared -o xd.dll xd.go
WORK=/var/folders/pm/69tdsm8j5f991wf8pb2txpf80000gn/T/go-build935584038
mkdir -p $WORK/b026/
cd /usr/local/Cellar/go/1.10.3/libexec/src/runtime/cgo
CGO_LDFLAGS='"-g" "-O2"' /usr/local/Cellar/go/1.10.3/libexec/pkg/tool/darwin_amd64/cgo -objdir $WORK/b026/ -importpath runtime/cgo -import_runtime_cgo=false -import_syscall=false -exportheader=$WORK/b026/_cgo_install.h -- -I $WORK/b026/ -g -O2 -Wall -Werror ./cgo.go
cd $WORK
i686-w64-mingw32-gcc -fno-caret-diagnostics -c -x c - || true
i686-w64-mingw32-gcc -Qunused-arguments -c -x c - || true
i686-w64-mingw32-gcc -fdebug-prefix-map=a=b -c -x c - || true
i686-w64-mingw32-gcc -gno-record-gcc-switches -c -x c - || true
cd $WORK/b026
i686-w64-mingw32-gcc -I /usr/local/Cellar/go/1.10.3/libexec/src/runtime/cgo -m32 -mthreads -fmessage-length=0 -fdebug-prefix-map=$WORK/b026=/tmp/go-build -gno-record-gcc-switches -I ./ -g -O2 -Wall -Werror -o ./_x001.o -c _cgo_export.c
i686-w64-mingw32-gcc -I /usr/local/Cellar/go/1.10.3/libexec/src/runtime/cgo -m32 -mthreads -fmessage-length=0 -fdebug-prefix-map=$WORK/b026=/tmp/go-build -gno-record-gcc-switches -I ./ -g -O2 -Wall -Werror -o ./_x002.o -c cgo.cgo2.c
cd /usr/local/Cellar/go/1.10.3/libexec/src/runtime/cgo
i686-w64-mingw32-gcc -I . -m32 -mthreads -fmessage-length=0 -fdebug-prefix-map=$WORK/b026=/tmp/go-build -gno-record-gcc-switches -I $WORK/b026/ -g -O2 -Wall -Werror -o $WORK/b026/_x003.o -c gcc_context.c
i686-w64-mingw32-gcc -I . -m32 -mthreads -fmessage-length=0 -fdebug-prefix-map=$WORK/b026=/tmp/go-build -gno-record-gcc-switches -I $WORK/b026/ -g -O2 -Wall -Werror -o $WORK/b026/_x004.o -c gcc_libinit_windows.c
i686-w64-mingw32-gcc -I . -m32 -mthreads -fmessage-length=0 -fdebug-prefix-map=$WORK/b026=/tmp/go-build -gno-record-gcc-switches -I $WORK/b026/ -g -O2 -Wall -Werror -o $WORK/b026/_x005.o -c gcc_util.c
i686-w64-mingw32-gcc -I . -m32 -mthreads -fmessage-length=0 -fdebug-prefix-map=$WORK/b026=/tmp/go-build -gno-record-gcc-switches -I $WORK/b026/ -g -O2 -Wall -Werror -o $WORK/b026/_x006.o -c gcc_windows_386.c
i686-w64-mingw32-gcc -I . -m32 -mthreads -fmessage-length=0 -fdebug-prefix-map=$WORK/b026=/tmp/go-build -gno-record-gcc-switches -I $WORK/b026/ -g -O2 -Wall -Werror -o $WORK/b026/_x007.o -c gcc_386.S
cd $WORK/b026
i686-w64-mingw32-gcc -I /usr/local/Cellar/go/1.10.3/libexec/src/runtime/cgo -m32 -mthreads -fmessage-length=0 -fdebug-prefix-map=$WORK/b026=/tmp/go-build -gno-record-gcc-switches -I ./ -g -O2 -Wall -Werror -o ./_cgo_main.o -c _cgo_main.c
cd /usr/local/Cellar/go/1.10.3/libexec/src/runtime/cgo
i686-w64-mingw32-gcc -I . -m32 -mthreads -fmessage-length=0 -fdebug-prefix-map=$WORK/b026=/tmp/go-build -gno-record-gcc-switches -o $WORK/b026/cgo.o $WORK/b026/_cgo_main.o $WORK/b026/_x001.o $WORK/b026/_x002.o $WORK/b026/_x003.o $WORK/b026/_x004.o $WORK/b026/_x005.o $WORK/b026/_x006.o $WORK/b026/_x007.o -g -O2
/usr/local/Cellar/go/1.10.3/libexec/pkg/tool/darwin_amd64/cgo -dynpackage cgo -dynimport $WORK/b026/cgo.o -dynout $WORK/b026/_cgo_import.go -dynlinker
mkdir -p $WORK/b001/
cd /Users/caisong/go/src/xd
CGO_LDFLAGS='"-g" "-O2"' /usr/local/Cellar/go/1.10.3/libexec/pkg/tool/darwin_amd64/cgo -objdir $WORK/b001/ -importpath command-line-arguments -exportheader=$WORK/b001/_cgo_install.h -- -I/usr/local/opt/wine/include/wine/windows -I $WORK/b001/ -g -O2 ./xd.go
cd $WORK/b001
i686-w64-mingw32-gcc -I /Users/caisong/go/src/xd -m32 -mthreads -fmessage-length=0 -fdebug-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I/usr/local/opt/wine/include/wine/windows -I ./-g -O2 -o ./_x001.o -c _cgo_export.c
i686-w64-mingw32-gcc -I /Users/caisong/go/src/xd -m32 -mthreads -fmessage-length=0 -fdebug-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I/usr/local/opt/wine/include/wine/windows -I ./-g -O2 -o ./_x002.o -c xd.cgo2.c
i686-w64-mingw32-gcc -I /Users/caisong/go/src/xd -m32 -mthreads -fmessage-length=0 -fdebug-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I/usr/local/opt/wine/include/wine/windows -I ./-g -O2 -o ./_cgo_main.o -c _cgo_main.c
cd /Users/caisong/go/src/xd
i686-w64-mingw32-gcc -I . -m32 -mthreads -fmessage-length=0 -fdebug-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -o $WORK/b001/cgo.o $WORK/b001/_cgo_main.o $WORK/b001/_x001.o $WORK/b001/_x002.o -g -O2
/usr/local/Cellar/go/1.10.3/libexec/pkg/tool/darwin_amd64/cgo -dynpackage main -dynimport $WORK/b001/cgo.o -dynout $WORK/b001/_cgo_import.go
cat >$WORK/b001/importcfg << 'EOF' # internal

import config

packagefile fmt=/Users/caisong/Library/Caches/go-build/a4/a44bac1cfef3c82f15cba91c14f31a30c7dbce5c068bcabcbbe6de8a430d753e-d
packagefile runtime/cgo=/Users/caisong/Library/Caches/go-build/29/298338e2cf934d739e451648ce8197dc03853c2f4199f3f40a00de781950faa5-d
packagefile syscall=/Users/caisong/Library/Caches/go-build/95/956e044da3690b757f01614ce5c33d52b97bc4e30e07ede67d818611c74c8bd7-d
packagefile runtime=/Users/caisong/Library/Caches/go-build/d8/d80e9a1b1d3ea8542483303482b2998a56353c924a2550fc6bf7a0ce1b9243dd-d
EOF
/usr/local/Cellar/go/1.10.3/libexec/pkg/tool/darwin_amd64/compile -o $WORK/b001/pkg.a -trimpath $WORK/b001 -p main -buildid OZxdgFEkEyn80DSh6Odc/OZxdgFEkEyn80DSh6Odc -goversion go1.10.3 -D _/Users/caisong/go/src/xd -importcfg $WORK/b001/importcfg -pack -c=4 $WORK/b001/_cgo_gotypes.go $WORK/b001/xd.cgo1.go $WORK/b001/_cgo_import.go
/usr/local/Cellar/go/1.10.3/libexec/pkg/tool/darwin_amd64/pack r $WORK/b001/pkg.a $WORK/b001/_x001.o $WORK/b001/_x002.o # internal
/usr/local/Cellar/go/1.10.3/libexec/pkg/tool/darwin_amd64/buildid -w $WORK/b001/pkg.a # internal
cp $WORK/b001/pkg.a /Users/caisong/Library/Caches/go-build/e4/e4f8bfe7d713435283576b7c0c8cd15507d647f7f1b126c7896330b676dea733-d # internal
cat >$WORK/b001/importcfg.link << 'EOF' # internal
packagefile command-line-arguments=$WORK/b001/pkg.a
packagefile fmt=/Users/caisong/Library/Caches/go-build/a4/a44bac1cfef3c82f15cba91c14f31a30c7dbce5c068bcabcbbe6de8a430d753e-d
packagefile runtime/cgo=/Users/caisong/Library/Caches/go-build/29/298338e2cf934d739e451648ce8197dc03853c2f4199f3f40a00de781950faa5-d
packagefile syscall=/Users/caisong/Library/Caches/go-build/95/956e044da3690b757f01614ce5c33d52b97bc4e30e07ede67d818611c74c8bd7-d
packagefile runtime=/Users/caisong/Library/Caches/go-build/d8/d80e9a1b1d3ea8542483303482b2998a56353c924a2550fc6bf7a0ce1b9243dd-d
packagefile errors=/Users/caisong/Library/Caches/go-build/02/027bc4691bda850d5ff03a480d30a168a26f7611082b248782a96c566a306fc5-d
packagefile io=/Users/caisong/Library/Caches/go-build/ef/efcea26cf9e2b857e8476d8622aa8427fd6ca1f70d1664a66a0cd2a43c67ee59-d
packagefile math=/Users/caisong/Library/Caches/go-build/f9/f995d999dd333e1e304a26edf6815905648e9112d6db4b8ef0dcdb5c598d4f3e-d
packagefile os=/Users/caisong/Library/Caches/go-build/e0/e0ea41106aac0f80c0a64942270f9cd90de46af047a1c489e193f661847e85f0-d
packagefile reflect=/Users/caisong/Library/Caches/go-build/82/8233643ac9321813a83eaa6fd76d1f838ed9d92f0fc1bbb45a2c50e50a745ade-d
packagefile strconv=/Users/caisong/Library/Caches/go-build/8f/8f0292b355c63b0c89d48484d32575a2407eaa1c051fb3288b8ddb2bdd99400c-d
packagefile sync=/Users/caisong/Library/Caches/go-build/5c/5c7e94fec559568cd8390fa96ebe4aed0920ed3250e6eff852c99a6cf218fd4d-d
packagefile unicode/utf8=/Users/caisong/Library/Caches/go-build/8f/8ffa5b4700120706654ead156e56f4e45492aa41d74a4b875866e4f999aa5f6b-d
packagefile internal/race=/Users/caisong/Library/Caches/go-build/47/47f2065dfe69f9d7df713d123ec099cb33b12b823f4629252489abb4a7acd0de-d
packagefile internal/syscall/windows/sysdll=/Users/caisong/Library/Caches/go-build/4c/4cfdc9769a73b5abe9c12309cb58014c51148fbe04e4714c16dc5d6d7fe4c367-d
packagefile sync/atomic=/Users/caisong/Library/Caches/go-build/a8/a84d08e53ab8dbfeea99544106ac5c2d74215ad2fa8324cc4499d2197424c009-d
packagefile unicode/utf16=/Users/caisong/Library/Caches/go-build/b3/b3562bff97d2f304b67b5a089f45f4a95ff2c654b1c593304a6eaf450a9351d6-d
packagefile runtime/internal/atomic=/Users/caisong/Library/Caches/go-build/36/36e8f466d9a36518d6c433e3e1666f873c689b9d3de26fdc7904735b703831eb-d
packagefile runtime/internal/sys=/Users/caisong/Library/Caches/go-build/33/33cc8225528ca94eb0059795319e9cf0f449b568923bc93d073d9f3ba80f56c5-d
packagefile internal/poll=/Users/caisong/Library/Caches/go-build/d9/d90f6fab63de36860e8a8cec4a262ad9c02d7dedb1a160c936c92174ed806a87-d
packagefile internal/syscall/windows=/Users/caisong/Library/Caches/go-build/1a/1a24b9fd1ebe498aeea41dcf9f5b0e91082269e36bd670904f0dcb303f9c1dc4-d
packagefile internal/testlog=/Users/caisong/Library/Caches/go-build/16/163bfde44ea3946f76840eb4e853bfc59c171a12f96434ce7e1ca803db282366-d
packagefile time=/Users/caisong/Library/Caches/go-build/d7/d7f015f0c3a13dcf395c88929246776e2a439f1957c7eef9c26f31fb24a13e95-d
packagefile unicode=/Users/caisong/Library/Caches/go-build/25/2522a141d59da8187017314c650ed4c20387cb3700758ec82d2101d336dc328d-d
packagefile internal/syscall/windows/registry=/Users/caisong/Library/Caches/go-build/4a/4aca3afdd1a9bba74b97d3fe95e1d1d2df03f71af27aabd782ac14d4a6c0de81-d
EOF
mkdir -p $WORK/b001/exe/
cd $WORK/b001/exe/
/usr/local/Cellar/go/1.10.3/libexec/pkg/tool/darwin_amd64/link -o xd.dll -importcfg $WORK/b001/importcfg.link -buildmode=c-shared -buildid=MZmWqmpHmIDsoFVL-sxF/OZxdgFEkEyn80DSh6Odc/8FcQGI01ytjcdca3kEcR/MZmWqmpHmIDsoFVL-sxF -s -w -extld=i686-w64-mingw32-gcc $WORK/b001/pkg.a
/usr/local/Cellar/go/1.10.3/libexec/pkg/tool/darwin_amd64/buildid -w $WORK/b001/exe/xd.dll # internal
mv $WORK/b001/_cgo_install.h xd.h
mv $WORK/b001/exe/xd.dll xd.dll
rm -r $WORK/b001/
`

Run test this dll

build everything it's ok . but test this dll, it's block
wine rundll32 xd.dll,Hello or windows cmd run this test , nothing todo and holding to this, application not exit .

@ianlancetaylor ianlancetaylor changed the title Mac os x go use mingw32 build windows dll failed. cmd/link: Mac os x go use mingw32 build windows dll failed Jul 11, 2018
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Jul 11, 2018
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jul 11, 2018

Does it work if you do everything natively on Windows? That is, is this a problem with Windows DLLs, or is this a problem with using a cross-compiler from MacOS?

How exactly are you trying to use the generated DLL? Simply running it is not expected to work. You are expected to open it from a C program.

You are likely to get better answers for this on a forum; see https://golang.org/wiki/Questions .

@xs23933

This comment has been minimized.

Copy link
Author

@xs23933 xs23933 commented Jul 21, 2018

Thank you! i will be go windows build test.

@xs23933 xs23933 closed this Jul 21, 2018
@xs23933

This comment has been minimized.

Copy link
Author

@xs23933 xs23933 commented Jul 21, 2018

i'm just build dll

@xs23933 xs23933 reopened this Jul 21, 2018
@xs23933 xs23933 closed this Jul 21, 2018
@golang golang locked and limited conversation to collaborators Jul 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.