Anyone successfully connecting to Oracle (11g) from Go?

3,011 views
Skip to first unread message

Ron Gidron

unread,
May 29, 2014, 1:18:31 PM5/29/14
to golan...@googlegroups.com
I am running OS X 10.9.3 and attempting to work with an amazon RDS instance. I have instantclient installed and working properly but am hitting walls trying to setup basic connectivity to it from my Go environment. I tried using both an ODBC driver (failed to install with missing .h files complaints) and also tried https://github.com/tgulacsi/goracle with no luck. 
Is anyone out these setup with Go server connected to Oracle (from a Mac?) and willing to share some code snippets / install directions?

Thanks!
--Ron

Tamás Gulácsi

unread,
May 29, 2014, 4:20:55 PM5/29/14
to golan...@googlegroups.com
Hi,

What's the errors?
goracle needs to have installed Oracle DB or installed InstantClient, and to have proper CGO_LDFLAGS and CGO_CFLAGS settings.

Have you tried https://github.com/tgulacsi/goracle/#mac-os-x ?

Th3x0d3r

unread,
May 29, 2014, 9:58:04 PM5/29/14
to golan...@googlegroups.com
Hello there,  give a try:  


As Tamas wrote, you need InstantClient and set properly CGO_LDFLAGS and CGO_CFLAGS.

Good luck ! 

Nathaniel Nutter

unread,
May 29, 2014, 11:23:27 PM5/29/14
to golang-nuts
I don't know if it's still the case but there have been issues with the Oracle InstantClient drivers on OS X in the past few months. If I recall correctly I think it was that the 64-bit drivers didn't work on Lion or newer. Make sure you validate that your InstantClient install is working; I think by using sqlplus to connect.

Robert Johnstone

unread,
May 30, 2014, 9:57:13 AM5/30/14
to golan...@googlegroups.com
I'm successfully connecting to Oracle using ODBC.  However, I'm not certain that my ODBC wrapper is the most mature.

http://godoc.org/bitbucket.org/rj/odbc3-go

Ron Gidron

unread,
May 31, 2014, 5:59:53 AM5/31/14
to Th3x0d3r, golan...@googlegroups.com
Must be some kind of path issue. I keep getting a missing oci.h when running go get. My environment setting looks good. sqlplus works fine.
Thanks for all your comments and suggestions, I'll play with it some more.

Thanks
--Ron
Kind Regards,
--Ron

Sent from Mailbox for iPhone.
Please excuse grammar and occasional spelling mistakes.


--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/fcFJSNV5L7o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ron Gidron

unread,
May 31, 2014, 9:06:14 AM5/31/14
to golan...@googlegroups.com
My program looks like so:
package main 

import (
"database/sql"
"fmt"
"os"
)

func func main() {
}

When I try to execute it with go run I get this error:

# github.com/tgulacsi/goracle/oracle

error: error reading '/Users/rongidron/instantclient_11_2/instantclient_11_2/sdk/include'

1 error generated.

connection.go:22:10: fatal error: 'oci.h' file not found

#include <oci.h>

         ^


Here are my CGO settings: (set | grep CGO)

CGO_CFLAGS=/Users/rongidron/instantclient_11_2/instantclient_11_2/sdk/include

CGO_LDFLAGS=/Users/rongidron/instantclient_11_2/instantclient_11_2

ls $CGO_CFLAGS 

ldap.h occiAQ.h occiObjects.h ociap.h ocidfn.h ocixstream.h orid.h xa.h

nzerror.h occiCommon.h oci.h ociapr.h ociextp.h odci.h orl.h

nzt.h occiControl.h oci1.h ocidef.h ocikpr.h oratypes.h oro.h

occi.h occiData.h oci8dp.h ocidem.h ocixmldb.h ori.h ort.h


so I am not sure what is up...

Tamás Gulácsi

unread,
May 31, 2014, 3:12:51 PM5/31/14
to golan...@googlegroups.com
Read the docs (https://github.com/tgulacsi/goracle#mac-os-x)! That -L and -I is not just decorations in CGO_LDFLAGS and CGO_CFLAGS!
Try with 

export CGO_CFLAGS=-I/Users/rongidron/instantclient_11_2/instantclient_11_2/sdk/include
export CGO_LDFLAGS=-L/Users/rongidron/instantclient_11_2/instantclient_11_2

Ron Gidron

unread,
Jun 1, 2014, 5:27:12 AM6/1/14
to golan...@googlegroups.com
Thanks Tamas. 

Now I get:

could not determine kind of name for C.OCIBreak

could not determine kind of name for C.OCITransRollback

could not determine kind of name for C.OCIPing

could not determine kind of name for C.setXID

could not determine kind of name for C.OCITransStart

could not determine kind of name for C.OCIServerDetach

Ron Gidron

unread,
Jun 1, 2014, 5:29:48 AM6/1/14
to golan...@googlegroups.com
Hi Th3x0d3r :-)

I get an error:

# pkg-config --cflags oci8

Package oci8 was not found in the pkg-config search path.

Perhaps you should add the directory containing `oci8.pc'

to the PKG_CONFIG_PATH environment variable

No package 'oci8' found

exit status 1

I have instantclient 11g installed and sqlplus is working fine..

my CGO_LDFLAGS and CGO_CFLAGS are set..


Thanks

Tamás Gulácsi

unread,
Jun 2, 2014, 5:06:21 AM6/2/14
to golan...@googlegroups.com
Hi,


2014. június 1., vasárnap 11:27:12 UTC+2 időpontban Ron Gidron a következőt írta:
Thanks Tamas. 

Now I get:

could not determine kind of name for C.OCIBreak

could not determine kind of name for C.OCITransRollback

could not determine kind of name for C.OCIPing

could not determine kind of name for C.setXID

could not determine kind of name for C.OCITransStart

could not determine kind of name for C.OCIServerDetach

Would you be so kind to send the FULL output of the command(s) you are running?
If you use the go tools (go get or go build), then please add the -x flag to them, to see what are they doing.

"could not determine kind of name": I haven't seen such messages yet.
What is the output of "go env"?
What is the output of gcc --version ?
Maybe you use clang?
 

Tamás Gulácsi

unread,
Jun 2, 2014, 7:07:22 AM6/2/14
to golan...@googlegroups.com
If I don't set CGO_CFLAGS or CGO_LDFLAGS, I get:

tgulacsi@nb-tgulacsi-nell:~/src/github.com/tgulacsi/goracle$ go build ./oracle
oracle/connection.go:23:17: fatal error: oci.h: No such file or directory
 #include <oci.h>
                 ^
compilation terminated.


Buf if I set it:

tgulacsi@nb-tgulacsi-nell:~/src/github.com/tgulacsi/goracle$ . ./env
go build ./oracle
cdir=/usr/include/oracle/11.2/client64 ldir=/usr/lib/oracle/11.2/client64/lib
export ORACLE_HOME=
export CGO_CFLAGS=-I/usr/include/oracle/11.2/client64
export CGO_LDFLAGS=-L/usr/lib/oracle/11.2/client64/lib


tgulacsi@nb-tgulacsi-nell:~/src/github.com/tgulacsi/goracle$ go build -x ./oracle
WORK=/tmp/go-build429665968
/usr/lib/go/pkg/tool/linux_amd64/cgo -objdir $WORK/github.com/tgulacsi/goracle/oracle/_obj/ -- -I $WORK/github.com/tgulacsi/goracle/oracle/_obj/ -I/usr/include/oracle/11.2/client64 connection.go cursor.go cursorvar.go datetimevar.go environment.go externallobvar.go lob_ctest.go lobvar.go longvar.go numbervar.go stringvar.go variable.go
/usr/lib/go/pkg/tool/linux_amd64/6c -F -V -w -I $WORK/github.com/tgulacsi/goracle/oracle/_obj/ -I /usr/lib/go/pkg/linux_amd64 -o $WORK/github.com/tgulacsi/goracle/oracle/_obj/_cgo_defun.6 -D GOOS_linux -D GOARCH_amd64 $WORK/github.com/tgulacsi/goracle/oracle/_obj/_cgo_defun.c
gcc -I . -g -O2 -fPIC -m64 -pthread -print-libgcc-file-name
gcc -I . -g -O2 -fPIC -m64 -pthread -I $WORK/github.com/tgulacsi/goracle/oracle/_obj/ -I/usr/include/oracle/11.2/client64 -o $WORK/github.com/tgulacsi/goracle/oracle/_obj/_cgo_main.o -c $WORK/github.com/tgulacsi/goracle/oracle/_obj/_cgo_main.c
gcc -I . -g -O2 -fPIC -m64 -pthread -I $WORK/github.com/tgulacsi/goracle/oracle/_obj/ -I/usr/include/oracle/11.2/client64 -o $WORK/github.com/tgulacsi/goracle/oracle/_obj/_cgo_export.o -c $WORK/github.com/tgulacsi/goracle/oracle/_obj/_cgo_export.c
gcc -I . -g -O2 -fPIC -m64 -pthread -I $WORK/github.com/tgulacsi/goracle/oracle/_obj/ -I/usr/include/oracle/11.2/client64 -o $WORK/github.com/tgulacsi/goracle/oracle/_obj/cursor.cgo2.o -c $WORK/github.com/tgulacsi/goracle/oracle/_obj/cursor.cgo2.c
gcc -I . -g -O2 -fPIC -m64 -pthread -I $WORK/github.com/tgulacsi/goracle/oracle/_obj/ -I/usr/include/oracle/11.2/client64 -o $WORK/github.com/tgulacsi/goracle/oracle/_obj/lobvar.cgo2.o -c $WORK/github.com/tgulacsi/goracle/oracle/_obj/lobvar.cgo2.c
gcc -I . -g -O2 -fPIC -m64 -pthread -I $WORK/github.com/tgulacsi/goracle/oracle/_obj/ -I/usr/include/oracle/11.2/client64 -o $WORK/github.com/tgulacsi/goracle/oracle/_obj/longvar.cgo2.o -c $WORK/github.com/tgulacsi/goracle/oracle/_obj/longvar.cgo2.c
gcc -I . -g -O2 -fPIC -m64 -pthread -I $WORK/github.com/tgulacsi/goracle/oracle/_obj/ -I/usr/include/oracle/11.2/client64 -o $WORK/github.com/tgulacsi/goracle/oracle/_obj/variable.cgo2.o -c $WORK/github.com/tgulacsi/goracle/oracle/_obj/variable.cgo2.c
gcc -I . -g -O2 -fPIC -m64 -pthread -o $WORK/github.com/tgulacsi/goracle/oracle/_obj/_cgo_.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/_cgo_main.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/_cgo_export.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/connection.cgo2.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/cursor.cgo2.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/cursorvar.cgo2.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/datetimevar.cgo2.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/environment.cgo2.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/externallobvar.cgo2.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/lob_ctest.cgo2.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/lobvar.cgo2.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/longvar.cgo2.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/numbervar.cgo2.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/stringvar.cgo2.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/variable.cgo2.o -L/usr/lib/oracle/11.2/client64/lib -lclntsh -lclntsh -lclntsh -lclntsh -lclntsh -lclntsh -lclntsh -lclntsh -lclntsh -lclntsh -lclntsh -lclntsh
/usr/lib/go/pkg/tool/linux_amd64/6c -F -V -w -I $WORK/github.com/tgulacsi/goracle/oracle/_obj/ -I /usr/lib/go/pkg/linux_amd64 -o $WORK/github.com/tgulacsi/goracle/oracle/_obj/_cgo_import.6 -D GOOS_linux -D GOARCH_amd64 $WORK/github.com/tgulacsi/goracle/oracle/_obj/_cgo_import.c
gcc -I . -g -O2 -fPIC -m64 -pthread -o $WORK/github.com/tgulacsi/goracle/oracle/_obj/_all.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/_cgo_export.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/connection.cgo2.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/cursor.cgo2.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/cursorvar.cgo2.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/datetimevar.cgo2.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/environment.cgo2.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/externallobvar.cgo2.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/lob_ctest.cgo2.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/lobvar.cgo2.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/longvar.cgo2.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/numbervar.cgo2.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/stringvar.cgo2.o $WORK/github.com/tgulacsi/goracle/oracle/_obj/variable.cgo2.o -L/usr/lib/oracle/11.2/client64/lib -Wl,-r -nostdlib /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc.a
/usr/lib/go/pkg/tool/linux_amd64/6g -o $WORK/github.com/tgulacsi/goracle/oracle/_obj/_go_.6 -p github.com/tgulacsi/goracle/oracle -D _/home/tgulacsi/src/github.com/tgulacsi/goracle/oracle -I $WORK -I /home/tgulacsi/pkg/linux_amd64 ./debug_notrace.go ./error.go $WORK/github.com/tgulacsi/goracle/oracle/_obj/_cgo_gotypes.go $WORK/github.com/tgulacsi/goracle/oracle/_obj/connection.cgo1.go $WORK/github.com/tgulacsi/goracle/oracle/_obj/cursor.cgo1.go $WORK/github.com/tgulacsi/goracle/oracle/_obj/cursorvar.cgo1.go $WORK/github.com/tgulacsi/goracle/oracle/_obj/datetimevar.cgo1.go $WORK/github.com/tgulacsi/goracle/oracle/_obj/environment.cgo1.go $WORK/github.com/tgulacsi/goracle/oracle/_obj/externallobvar.cgo1.go $WORK/github.com/tgulacsi/goracle/oracle/_obj/lob_ctest.cgo1.go $WORK/github.com/tgulacsi/goracle/oracle/_obj/lobvar.cgo1.go $WORK/github.com/tgulacsi/goracle/oracle/_obj/longvar.cgo1.go $WORK/github.com/tgulacsi/goracle/oracle/_obj/numbervar.cgo1.go $WORK/github.com/tgulacsi/goracle/oracle/_obj/stringvar.cgo1.go $WORK/github.com/tgulacsi/goracle/oracle/_obj/variable.cgo1.go


Something along these lines may help us help you :)

Ron Gidron

unread,
Jun 2, 2014, 8:13:46 AM6/2/14
to Tamás Gulácsi, golan...@googlegroups.com
Hi Tamas,

Thanks very much for the help. unfortunately I seam to have completely messed up my instantclient installation while trying to fix this problem. I resorted to remove and re-install instantclient and the SDK - run into an LYLD_LIBRARY_PATH issue and foolishly executed a script I found on some blog which has somehow altered the linking of the libraries so now when I try to run sqlplus I get silly errors of not being abale to load dynamic libraries from a path that doesn't exist on my machine... I will have to deal with this first I guess. will report back when Iv"e solved that and on the status of goracle..


Thanks,
--Ron 


--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/fcFJSNV5L7o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Kind Regards,
-- Ron Gidron
E: r...@rongidron.me | M: +972 546919100 | Skype: RGidron

Ron Gidron

unread,
Jun 4, 2014, 12:25:42 PM6/4/14
to golan...@googlegroups.com
Hi Tamas,

OK - I fixed my sqlplus installation and got back to this error. 
I think you were correct about me using clang but not sure what it means or what to do about it.. 
Here is the output of go build -x

go build -x

WORK=/var/folders/95/g05l4r0j0dj5wml54jq8c_hr0000gn/T/go-build354543896

cd /Users/rongidron/develop/go/src/github.com/tgulacsi/goracle/oracle

/usr/local/Cellar/go/1.1.2/libexec/pkg/tool/darwin_amd64/cgo -objdir $WORK/github.com/tgulacsi/goracle/oracle/_obj/ -- -I/usr/local/oracle/product/instantclient_64/11.2.0.4.0/lib/sdk/include -I $WORK/github.com/tgulacsi/goracle/oracle/_obj/ connection.go cursor.go cursorvar.go datetimevar.go environment.go externallobvar.go lob_ctest.go lobvar.go longvar.go numbervar.go stringvar.go variable.go

# github.com/tgulacsi/goracle/oracle

could not determine kind of name for C.OCISessionBegin

could not determine kind of name for C.OCIServerAttach

could not determine kind of name for C.OCITransStart

could not determine kind of name for C.OCITransPrepare

could not determine kind of name for C.OCIClientVersion

could not determine kind of name for C.OCITransCommit


and here is what gcc -version looks like:

gcc -version

clang: error: unknown argument: '-version' [-Wunused-command-line-argument-hard-error-in-future]

clang: note: this will be a hard error (cannot be downgraded to a warning) in the future

clang: error: no input files


I think this may be the problem:

https://support.enthought.com/entries/26184115-GCC-Clang-and-Cython-in-OS-X-10-9-Mavericks


I appreciate it very much if you can help me.


Thanks!

Ron Gidron

unread,
Jun 4, 2014, 5:03:05 PM6/4/14
to golan...@googlegroups.com
OK so after a long debugging session I ened up finding that there are type mismatches happening when running go 1.3. I have (for now) updated my oci8 driver and filed a report here https://github.com/mattn/go-oci8/issues/27

Solved for me.

Thanks,
--Ron


On Thursday, May 29, 2014 8:18:31 PM UTC+3, Ron Gidron wrote:

Samy Sultan

unread,
Sep 7, 2020, 2:01:46 PM9/7/20
to golang-nuts
I make a new package go-ora it is pure go oracle client no need for instant client at all no need for environmental vars just 
go-get the package and run you program

Tamás Gulácsi

unread,
Sep 7, 2020, 2:16:19 PM9/7/20
to golang-nuts
Wow, have you reverse-engineered the Oracle SQL.NET connection? Or the Java thin client?
Is this legal at all?
Though I'd pay a limb for a C-less native, pure Go client...
Reply all
Reply to author
Forward
0 new messages