N
N
nurzhannogerbek2019-03-11 11:33:24
Oracle
nurzhannogerbek, 2019-03-11 11:33:24

How to build a golang project that uses CGO?

Hello! Please help me figure it out. I wrote a Golang application
on Windows 10 . This application uses several third-party libraries. One of them is goracle for connecting to Oracle database. The project is running locally. On my local machine (windows 10) I'm trying to build a binary with the following command:

$Env:GOOS = "linux"; $Env:GOARCH = "amd64"; go build

Unfortunately I see the following error:
# gopkg.in/goracle.v2
../gopkg.in/goracle.v2/orahlp.go:60:2: undefined: describeOnly
../gopkg.in/goracle.v2/orahlp.go:223:26: undefined: PlSQLArrays
../gopkg.in/goracle.v2/orahlp.go:246:32: undefined: VersionInfo
../gopkg.in/goracle.v2/orahlp.go:249:10: undefined: VersionInfo
../gopkg.in/goracle.v2/orahlp.go:255:32: undefined: VersionInfo
../gopkg.in/goracle.v2/orahlp.go:272:19: undefined: VersionInfo
../gopkg.in/goracle.v2/orahlp.go:273:31: undefined: ObjectType
../gopkg.in/goracle.v2/orahlp.go:274:31: undefined: Event
../gopkg.in/goracle.v2/orahlp.go:274:41: undefined: Subscription
../gopkg.in/goracle.v2/orahlp.go:284:27: undefined: conn
../gopkg.in/goracle.v2/orahlp.go:249:10: too many errors

I am going to use this binary on a production server (CentOS) in order to wrap it in Docker in the future.
Found a post with a similar problem. One of the comments says that some CGO is needed and it can be built directly in Docker-e. I have a question, how to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Pavlyuk, 2019-03-11
@pav5000

The easiest way for you to build this whole thing directly on CentOS.
CGO does not need to be assembled, it already works out of the box. It's just that you don't have the Linux binary libraries on your Windows machine that you need to build. So build under CentOS with oracle libraries installed.

V
Vladislav, 2019-03-11
@ghostiam

If you have a docker, you should try the xgo project ( https://github.com/karalabe/xgo )
I use it myself to compile projects from cgo to macos for linux x64/arm

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question