- Download Oracle Instant Client SDK, Basic-Lite
- TDM-GCC 64Bit Download
- pkg-config SO Thread
- pexports Download
- Extract instantclient into
C:\oracle\instantclient_12_1
- Install TDM-GCC into
C:\TDM-GCC-64
If you try to build without do this you'll face with "error adding symbols: File in wrong format".
and i'm realized
oci.lib
is under sdk/lib/msvc
directory and GCC
toolchain doesn't regconize archive library that build by Visual Studio so we have to reformat it by using pexport
For most convinient I'm using Git Bash
cd /c/oracle/instantclient_12_1
Prepare directory
mkdir -pv sdk/lib/gcc
Create definition file from dynamic link library
pexports oci.dll > oci.def
Create archive file (.a) from created definition file
dlltools -D oci.dll -d oci.def -l sdk/lib/gcc/liboci.a
Now we have archive that gcc regconize.
Add C:\oracle\instantclient_12_1
into you Windows PATH
fill C:\oracle\instantclient_12_1\oci8.pc
with content below.
ora=C:/oracle/instantclient_12_1/sdk
gcc=C:/TDM-GCC-64
oralib=${ora}/lib/gcc
orainclude=${ora}/include
gcclib=${gcc}/lib
gccinclude=${gcc}/include
glib_genmarshal=glib-genmarshal
gobject_query=gobject-query
glib_mkenums=glib-mkenums
Name: oci8
Description: Oracle database engine
Version: 12.1
Libs: -L${oralib} -L${gcclib} -loci
Libs.private:
Cflags: -I${orainclude} -I${gccinclude}
And now ...
go get -v github.com/mattn/go-oci8
In case you're using Visual Studio code here tasks.json for build
{
"taskName": "build",
"isBuildCommand": true,
"echoCommand": true,
"command": "go",
"args": [
"build",
"-x",
"-ldflags=-s -w",
"src/main.go"
],
"options": {
"cwd": "${workspaceRoot}",
"env": {
"GOOS": "windows",
"GOARCH": "amd64",
"GOPATH": "${workspaceRoot}",
"CGO_ENABLE": "1",
"PKG_CONFIG_PATH": "C:/oracle/instantclient_12_1"
}
}
}
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "{your program}",
"env": {
"GOPATH": "${workspaceRoot}",
"ORACLE_SID": "xe",
"ORACLE_HOME": "C:/oracle/instantclient_12_1",
"ORACLE_BASE": "C:/oracle/instantclient_12_1"
"NLS_LANG": ""
},
"args": [],
"showLog": true
}
]
}
Thank's, perfect.
If it does not work, try
copy oci8.pc to C:/TDM-GCC-64/lib/pkgconfig