Getting Started with Chilkat in the Go Language (Linux 64-bit)
This is a walkthrough for getting a “Hello World” working with Chilkat in the Go programming language.
We’ll start from scratch by downloading Go and getting a simple Hello World Go example working. Then we’ll install Chilkat and build and run an example program.
(1) My Go language installation will be in ~/langDists/go.
cd ~
mkdir langDists
cd langDists
(2) Download Go and unpack.
wget https://dl.google.com/go/go1.12.7.linux-amd64.tar.gz
tar xzf go1.12.7.linux-amd64.tar.gz
(3) Edit your .profile by adding these lines. Then restart your shell session..
(The GOPATH will be used in the next steps, but we’ll set it here..)
GOROOT=$HOME/langDists/go
PATH="$PATH:$GOROOT/bin"
GOPATH=$HOME/go
(4) Create a directory (~/go/src/hello) where we’ll create a simple “hello” Go program.
cd ~
mkdir go
cd go
mkdir src
cd src
mkdir hello
(5) Create the file ~/go/src/hello/hello.go containing this content
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
(6) Build and run
cd ~/go/src/hello
go build
./hello
If all is OK, proceed…
(7) Download chilkat_go.zip and unzip. (The download link should be updated to the latest version of Chilkat. See https://www.chilkatsoft.com/go.asp
cd $GOPATH/src
wget https://chilkatdownload.com/9.5.0.78/chilkat_go.zip
unzip chilkat_go.zip
(8) Download the Native “C” Chilkat Go library for 64-bit Linux
Make sure the Chilkat version matches the version downloaded for chilkat_go.zip.
cd $GOPATH/src
mkdir chilkatLib
cd chilkatLib
wget https://chilkatdownload.com/9.5.0.78/chilkatext-9.5.0-linux-x64-gcc.tar.gz
tar xzf chilkatext-9.5.0-linux-x64-gcc.tar.gz
(9) Set $CGO_LDFLAGS as shown here. (Add this line to your .bashrc)
export CGO_LDFLAGS="-L$HOME/go/chilkatLib/linux-x64-gcc -lchilkatext-9.5.0 -lresolv -lpthread -lstdc++"
(10) Build the “chilkat” package.
The “go build” will take some time.
cd $GOPATH/src/chilkat
go build
go install
(11) Build and Run an Example Program
cd $GOPATH/src/chilkat_example1
go build
./chilkat_example1
The output for the chilkat_example1 should be some XML followed by a line indicating “success”.