Reputation: 115
I'm trying to connect to a db2 using golang using https://bitbucket.org/phiggins/db2cli. While trying to follow the instructions, I run into this error
vendor/bitbucket.org/phiggins/db2cli/api/api_unix.go:12:11: fatal
error: 'sqlcli1.h' file not found
#include <sqlcli1.h>
^~~~~~~~~~~
1 error generated.
This is the script I tried to use
#!/bin/bash
DB2HOME=$HOME/sqllib
export CGO_LDFLAGS=-L$DB2HOME/lib
export CGO_CFLAGS=-I$DB2HOME/include
go install .
Could someone point me to what I need to do to use db2cli? I'm running this code on a macbook.
Upvotes: 0
Views: 2320
Reputation: 21
The driver I was using was github.com/ibmdb/go_ibm_db
, and I ended up solving the problem as follows:
import _ github.com/ibmdb/go_ibm_db
go mod tidy
go mod download
cd $GOPATH/pkg/mod/github.com/ibmdb/[email protected]/installer
sh setup.go
This script will download db2cli to the $GOPATH/pkg/mod/github.com/ibmdb
directory by default
sh setenv.sh
This script sets environment variables based on the current scenario, The key variables are: CGO_CFLAGS
, CGO_CFLAGS
, LD_LIBRARY_PATH
(linux), DYLD_LIBRARY_PATH
(mac)
Upvotes: 0
Reputation: 12267
To build golang with the phiggins db2cli , your workstation or server needs to have a Db2 product (e.g. a suitable client, or a server package) installed locally specifically to deliver the INCLUDE files and the library files for development with Db2.
The Db2-client software comes in different packages for different purposes, and a Db2-client also comes with a Db2-LUW server. For development purposes (i.e. to compile and link executable programs) you need the "IBM Data Server Driver package".
IBM describes the different Db2 client types at this link.
If your remote Db2-server runs on Linux/Unix/Windows, you can also try building golang-db2cli on that hostname and copy the build-targets to your workstation provided the server and workstation run the same distro and bitness and release and that the Db2 version/fixpack is identical to that of the client.
Otherwise you can download and install the relevant package from IBM's Fix Central website (registration required) , or from IBM's Passport Advantage website for registered entitled customers. The Db2-client download links are available currently at this link.
Upvotes: 3