Skip to content

Instantly share code, notes, and snippets.

@bearx3f
Last active September 16, 2017 16:56
Show Gist options
  • Save bearx3f/8f60a1c431fb0623af59b2a1c6248786 to your computer and use it in GitHub Desktop.
Save bearx3f/8f60a1c431fb0623af59b2a1c6248786 to your computer and use it in GitHub Desktop.

Install go-oci8 on Windows 64

Extract

  • Extract instantclient into C:\oracle\instantclient_12_1
  • Install TDM-GCC into C:\TDM-GCC-64

Convert .dll -> .a

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.

Setup Environment Variable

Add C:\oracle\instantclient_12_1 into you Windows PATH

Create pkg-config file

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}

GO! Get go-oci8

And now ...

go get -v github.com/mattn/go-oci8

Visual Studio Code's task

tasks.json // for compile

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"
        }
    }
}

launch.json // for debugging

{
    "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
        }
    ]
}
@bearx3f
Copy link
Author

bearx3f commented Sep 16, 2017

@amiracam something wrong with your oci.def could you show oci.def file's content.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment