Skip to content

Instantly share code, notes, and snippets.

@mnadel
Last active December 26, 2022 12:06
Show Gist options
  • Save mnadel/8678269 to your computer and use it in GitHub Desktop.
Save mnadel/8678269 to your computer and use it in GitHub Desktop.
go-oci8 on windows64

Prerequisites

Create a file called oci8.pc

ora=<instaclient-install-dir>
gcc=<tdm-gcc-install-dir>

oralib=${ora}\\sdk\\lib\\msvc
orainclude=${ora}\\sdk\\include

gcclib=${gcc}\\lib
gccinclude=${gcc}\\include

Name: OCI
Description: Oracle database engine
Version: 12.1
Libs: -L${oralib} -L${gcclib} -loci
Libs.private: 
Cflags: -I${orainclude} -I${gccinclude}

Make sure to use \\ as the path separator

Setup environment

  • set PATH=<tdm-gcc-install-dir>\bin;%PATH%
  • set PKG_CONFIG_PATH=<path-to->\oci8.pc

Build your app

  • go get github.com/mattn/go-oci8
  • go build -x your-prog.go

Note: -x will show you the underlying gcc/ld commands, which is incredibly useful for debugging

@novalagung
Copy link

Dear @mnadel, do you have some example on how to use go-oci8 on OSX environment?

I tried to connect using sqlplus scott/tiger@SHGU and it's working fine.

But whenever I try to run _example/oracle.go from go-oci8, it always ended up "ORA-12545: Connect failed because target host or object does not exist".

I already set the variables.

export GO_OCI8_CONNECT_STRING="(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.210)(PORT=1521)))(CONNECT_DATA=(SID=ORCL)(SERVER=DEDICATED)(SERVICE_NAME=orcl.shgu.local)))"
export ORACLE_SID="ORCL"

could you advise me how to solve this?

@jpillan
Copy link

jpillan commented Dec 4, 2015

getting "error adding symbols: File in wrong format". Any idea?

@ajaivar
Copy link

ajaivar commented Mar 25, 2016

Try with format export GO_OCI8_CONNECT_STRING=user/name@host:port/sid

@msaron
Copy link

msaron commented Apr 17, 2018

I am using Windows 10. I did exactly as you described above but am getting the following error:

# pkg-config --cflags oci8
pkg-config: exit status 3221225595

My oci8.pc config file is as follows:

ora=C:\oracle\instantclient_12_2
gcc=C:\TDM-GCC-64

oralib=${ora}\sdk\lib\msvc
orainclude=${ora}\sdk\include

gcclib=${gcc}\lib
gccinclude=${gcc}\include

Name: OCI
Description: Oracle database engine
Version: 12.2
Libs: -L${oralib} -L${gcclib} -loci
Libs.private:
Cflags: -I${orainclude} -I${gccinclude}

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