alexbrainman / odbc

odbc driver written in go
BSD 3-Clause "New" or "Revised" License
352 stars 140 forks source link

Can't find include files when building go project #109

Open kieronb56 opened 6 years ago

kieronb56 commented 6 years ago

When I installed unixODBC (2.3.6) I used a --prefix, so I guess I somehow need to pass this when running go build on a linux box? Can't see how to do this and we don't have permissions to install in the default directories.

alexbrainman commented 6 years ago

I always install unixODBC using OS package manager, so I do not know the answer to your question.

But, I suspect, you could change the source to specify whatever directory you want:

$ pwd
/home/a/src/github.com/alexbrainman/odbc/api
$ grep FLAGS *
api_unix.go:// #cgo darwin LDFLAGS: -lodbc -L/opt/local/lib
api_unix.go:// #cgo darwin CFLAGS: -I/opt/local/include
api_unix.go:// #cgo linux LDFLAGS: -lodbc
mksyscall_unix.pl:// #cgo darwin LDFLAGS: -lodbc -L/opt/local/lib
mksyscall_unix.pl:// #cgo darwin CFLAGS: -I/opt/local/include
mksyscall_unix.pl:// #cgo linux LDFLAGS: -lodbc
zapi_unix.go:// #cgo darwin LDFLAGS: -lodbc -L/opt/local/lib
zapi_unix.go:// #cgo darwin CFLAGS: -I/opt/local/include
zapi_unix.go:// #cgo linux LDFLAGS: -lodbc
$ 

Alex

anomalousitem commented 6 years ago

You can also use environment variables which get appended to the cgo directives. No need to change the source directly. I was able to build with something like:

CGO_CFLAGS="-I/opt/local/include" CGO_LDFLAGS="-L/opt/local/lib" go build

From Command cgo:

When building, the CGO_CFLAGS, CGO_CPPFLAGS, CGO_CXXFLAGS, CGO_FFLAGS and CGO_LDFLAGS environment variables are added to the flags derived from these directives. Package-specific flags should be set using the directives, not the environment variables, so that builds work in unmodified environments.