IBM Support

Procedure to Install GoLang and go_ibm_db on M1 Architecture

How To


Summary

This article describes the steps to follow to install GoLang and go_ibm_db driver on M1 architecture along with necessary dependencies.

Objective

Installing Golang and go_ibm_db driver on M1 architecture

Environment

M1 Mac machine

Steps

1. Install gcc-8 on M1

 Warning: If you use the ARM version of homebrew (as recommended for M1 architectures) you will get the following error message:
$ brew install gcc-8
Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!
Please create a new installation in /opt/homebrew using one of the
"Alternative Installs" from:
  https://docs.brew.sh/Installation
You can migrate your previously installed formula list with:
  brew bundle dump
Install gcc-8 using homebrew (note: the x86_64 version of homebrew is needed for this, not the recommended ARM based homebrew).
Use the following procedure to install and use the x86_64 version of homebrew:
  • M1 brew is installed here:
    $ which brew
    /opt/homebrew/bin/brew
  • Install x86_64 brew under /usr/local/bin/brew
    arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  • Create an alias for the x86_64 brew, add following to the ~/.zshrc
    # brew hack for x86
    alias ibrew='arch -x86_64 /usr/local/bin/brew'
  • Install gcc-8 using the x86_64 homebrew:
    ibrew install gcc@8
  • Create a symbolic link to override my native ARM based gcc so my system can reference gcc-8
    sudo ln -s /usr/local/bin/gcc-8 /usr/local/bin/gcc
2. Installing Golang
  • Install the x86_64 version of Golang v1.18.8 on M1 (https://go.dev/dl/go1.18.8.darwin-amd64.pkg) or install the latest that is 1.20.1.
3. Setting up clidriver
  • Use the Curl command to download the new version of Clidriver
    curl -n https://github.com/ibmdb/db2drivers/blob/main/clidriver/macos64_odbc_cli.tar.gz -o clidriver.tar.gz
  • Extract and put the clidriver in the ibmdb folder:
    tar -xzvf macos64_odbc_cli.tar.gz /Users/<username>/go/pkg/mod/github.com/ibmdb
  • clear Go cache to delete pkg folder, download again by using
    go mod tidy
  • Export the following variables into the bashrc file:
    IBM_DB_HOME=<path to clidriver download path>
    CGO_CFLAGS=-I/Users/<username>/go/pkg/mod/github.com/ibmdb//clidriver/include
    CGO_LDFLAGS=-L/Users/<username>/go/pkg/mod/github.com/ibmdb/ /clidriver/lib
    DYLD_LIBRARY_PATH=/Users/<username>/go/pkg/mod/github.com/ibmdb/clidriver/lib:/usr/local/lib/gcc/8
  • Run this command in the terminal:
    install_name_tool -id /Users/<username>/go/pkg/mod/github.com/ibmdb/clidriver/lib/libdb2.dylib /Users/<username>/go/pkg/mod/github.com/ibmdb/clidriver/lib/libdb2.dylib
    
Troubleshooting:
  1. 'sqlcli1.h' file not found
    • Please check that the clidriver is present as ../pkg/mod/github.com/ibmdb/clidriver. If not please check if all the above steps are followed correctly.
    • If present, please validate that ../clidriver/include directory exists.
    • If clidriver/include is present, then check value of  “echo $CGO_CFLAGS” command. .zshrc file is for zsh. If it’s a different shell in use, then it will not be effective.
    • Run source ~/.bashrc or ~/.zshrc to solve this error.
    • Run Go Code
  2. "libgsk8sys.dylib" cannot be opened because the developer cannot be verified.
    • To solve this command run the following command:
      sudo xattr -rd com.apple.quarantine <path to libgsk8sys.dylib>

Document Location

Worldwide

[{"Type":"MASTER","Line of Business":{"code":"LOB10","label":"Data and AI"},"Business Unit":{"code":"BU053","label":"Cloud \u0026 Data Platform"},"Product":{"code":"SSEPDU","label":"Db2 Connect"},"ARM Category":[{"code":"a8m3p000000hBS5AAM","label":"Db2 Open Source Drivers"}],"ARM Case Number":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"All Versions"}]

Document Information

Modified date:
13 April 2023

UID

ibm16967551