mattn/go-oci8

window10 go build Windows to Linux failed,help me plz

NickEric opened this issue · 7 comments

Excuse me, please help me!!! I use go run main.go has no problem running the project program.

When I cross compile to Linux under win10, the following problems occur.
I looked up these issues:
https://github.com/mattn/go-oci8/issues/388
https://github.com/mattn/go-oci8/issues/399
https://github.com/mattn/go-oci8/issues/309
https://github.com/mattn/go-oci8/issues/342

I still can't solve the problem. I hope I can get help.

D:\projectfile>SET GOARCH=amd64

D:\projectfile>SET GOOS=linux

D:\projectfile>go build main.go
github.com/mattn/go-oci8
....\pkg\mod\github.com\mattn\go-oci8@v0.1.1\connector.go:14:10: undefined: Connector
....\pkg\mod\github.com\mattn\go-oci8@v0.1.1\connector.go:20:18: undefined: Connector
....\pkg\mod\github.com\mattn\go-oci8@v0.1.1\connector.go:21:9: undefined: Driver
....\pkg\mod\github.com\mattn\go-oci8@v0.1.1\connector.go:25:18: undefined: Connector
....\pkg\mod\github.com\mattn\go-oci8@v0.1.1\connector.go:30:11: undefined: Conn

The following is my project environment and configuration.

C:\Users\nk>go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\nk\AppData\Local\go-build
set GOENV=C:\Users\nk\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=D:\softwhere\GoWorkPlace\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=D:\softwhere\GoWorkPlace
set GOPRIVATE=
set GOPROXY=https://goproxy.cn,direct
set GOROOT=D:\softwhere\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\softwhere\go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.17.3
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
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\nk\AppData\Local\Temp\go-build1330894203=/tmp/go-build -gno-record-gcc-switches

oci8.pc

prefix=D:/softwhere/instantclient_11_2
exec_prefix=${prefix}
libdir=D:/softwhere/instantclient_11_2/sdk/lib/msvc
includedir=D:/softwhere/instantclient_11_2/sdk/include

glib_genmarshal=glib-genmarshal
gobject_query=gobject-query
glib_mkenums=glib-mkenums

Name: oci8
Description: oci8 library
Libs: -L${libdir} -loci
Cflags: -I${includedir}
Version: 12.1

C:\Users\nk>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=D:/softwhere/MinGW/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/8.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-8.1.0/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/c/mingw810/x86_64-810-win32-seh-rt_v6-rev0/mingw64 --enable-shared --enable-static --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=win32 --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-pkgversion='x86_64-win32-seh-rev0, Built by MinGW-W64 project' --with-bugurl=https://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -fno-ident -I/c/mingw810/x86_64-810-win32-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -fno-ident -I/c/mingw810/x86_64-810-win32-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS=' -I/c/mingw810/x86_64-810-win32-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' LDFLAGS='-pipe -fno-ident -L/c/mingw810/x86_64-810-win32-seh-rt_v6-rev0/mingw64/opt/lib -L/c/mingw810/prerequisites/x86_64-zlib-static/lib -L/c/mingw810/prerequisites/x86_64-w64-mingw32-static/lib '
Thread model: win32
gcc version 8.1.0 (x86_64-win32-seh-rev0, Built by MinGW-W64 project)

C:\Users\nk>pkg-config --cflags --libs oci8
-LD:/softwhere/MinGW/mingw64/lib -ID:/softwhere/instantclient_11_2/sdk/include -LD:/softwhere/instantclient_11_2/sdk/lib/msvc -LD:/softwhere/MinGW/mingw64/lib -loci

mattn commented

you are using host C compiler. you have to use cross C compiler instead for Linux.

@mattn

What should I do? SET CGO_ENABLED=1, Is that right?

mattn commented

Install C Compiler to generate ELF binary on Windows.

@mattn
Sorry,I still don't quite understand. I'm a rookie. Are there detailed steps or operation documents?

mattn commented

Go compiler on Windows can generate ELF binary for Linux. But go-oci8 is cgo module. cgo uses C compiler like gcc. However, gcc compiler you are using can not generate ELF binary. So you must install gcc cross compiler which can generate ELF binary.

If you can't find the cross C compiler, I suggest to use WSL on Windows.

@mattn
ok, thank you ,I'll try it. It's a little difficult for me. Thank you again

@mattn
hi @mattn ,you can close this issue. In Windows , I did not cross compile the project successfully for Linux. but I chose to develop the project under Linux system and compile the project, which has been successfully run in other Linux. Thank you again for your answer, which is very helpful to me.