Installing the Go Chilkat Package on MacOS
Prerequisites
The install script will first check to verify the following command are available on your MacOS system: unzip, curl, sha256sum, and tar. If any of the commands are not available, the installChilkat.sh will exit with an error message prior to doing anything.
Installing
Run the following to download, build, and install. The install script (shown below) will download the required Chilkat native "C" library based on the CPU architecture, and also the Chilkat Go sources. It will validate the SHA256 checksums against the expected values. If all is OK, the downloads are extracted and the Chilkat Go module is built.
cd ~/temp curl https://chilkatdownload.com/10.0.0/build_chilkat_go.zip -o build_chilkat_go.zip unzip build_chilkat_go.zip cd build_on_macos chmod a+x *.sh ./installChilkat.sh ./buildExample1.sh ./buildExample2.sh
The installChilkat.sh script contains the following:
#!/bin/bash # Installs Chilkat v10.0.0 Go module on MacOS # Change to any desired directory. installDir=~ #---------------------------------------- # Check if the "tar" command exists which tar # Check the exit status if [ $? -ne 0 ]; then echo "tar command does not exist." exit 1 fi #---------------------------------------- # Check if the "unzip" command exists which unzip # Check the exit status if [ $? -ne 0 ]; then echo "unzip command does not exist." exit 1 fi #---------------------------------------- # Check if the "curl" command exists which curl # Check the exit status if [ $? -ne 0 ]; then echo "curl command does not exist." exit 1 fi #---------------------------------------- # Check if the "sha256sum" command exists which sha256sum # Check the exit status if [ $? -ne 0 ]; then echo "sha256sum command does not exist." exit 1 fi # ------------------------------ echo "Installing to $installDir" # Create the install directory if needed. if [ ! -d "$installDir" ]; then if mkdir $installDir; then echo "Created $installDir" else echo "Failed to create $installDir" exit 1 fi fi cd $installDir # ------------------------------------------------------------------------- # Create the "chilkatsoft.com" directory underneath the install directory. if [ ! -d "chilkatsoft.com" ]; then if mkdir chilkatsoft.com; then echo "Created chilkatsoft.com" else echo "Failed to create chilkatsoft.com" exit 1 fi fi cd chilkatsoft.com # -------------------------------------------------------------------- # The native "C" library download is based on the machine architecture # Download and verify the SHA256 digest of the download is a expected. # Possible machine architectures are: # x86_64 # arm64 # If your machine architecture is different, please let Chilkat know. machineArch=`uname -m` if [ "$machineArch" = "x86_64" ]; then echo "x86_64" archSubdir=macosx-x86_64-clang curl https://chilkatdownload.com/10.0.0/chilkatext-macosx-x86_64-clang.tar.gz -o chilkat_native_c.tar.gz if [ $? -ne 0 ]; then echo "curl download of the Chilkat native "C" library failed." exit 1 fi digestSha256=`sha256sum chilkat_native_c.tar.gz` echo $digestSha256 if [[ $digestSha256 == *b51e3d3cb339beff7c3c3be8da2e4b41041b0a5d0578705583dd4911c3740dbb* ]]; then echo "Good, the SHA256 digest of chilkat_native_c.tar.gz is as expected." else echo "Digest of Chilkat native C library is not the expected value." exit 1 fi elif [ "$machineArch" = "arm64" ]; then echo "aarch64" archSubdir=macosx-arm64-clang curl https://chilkatdownload.com/10.0.0/chilkatext-macosx-arm64-clang.tar.gz -o chilkat_native_c.tar.gz if [ $? -ne 0 ]; then echo "curl download of the Chilkat native "C" library failed." exit 1 fi digestSha256=`sha256sum chilkat_native_c.tar.gz` echo $digestSha256 if [[ $digestSha256 == *b2b22726d120717fd2d1a7c072e978353f9187b892792ea8d50d89c73b8ccf19* ]]; then echo "Good, the SHA256 digest of chilkat_native_c.tar.gz is as expected." else echo "Digest of Chilkat native C library is not the expected value." exit 1 fi else echo "Unsupported architecture: $machineArch" exit 1 fi # --------------------------------------------------------- # Extract and rename the subdirectory to "native_c_lib" # # the resulting Chilkat native "C" static library is $installDir/chilkatsoft.com/native_c_lib/libchilkatext.a if [ -d "native_c_lib" ]; then rm -rf native_c_lib fi if [ -d "$archSubdir" ]; then rm -rf $archSubdir fi tar xvf chilkat_native_c.tar.gz if [ $? -ne 0 ]; then echo "extracting from .tar.gz failed." exit 1 fi mv $archSubdir native_c_lib rm -f chilkat_native_c.tar.gz # -------------------------------------------------------- # Delete the "chilkat", "chilkat_example1", and "chilkat_example2" subdirectories # from previous install attempts if they exist. # (at this point, we are in the $installDir/chilkatsoft.com directory) if [ -d "chilkat" ]; then rm -rf chilkat fi if [ -d "chilkat_example1" ]; then rm -rf chilkat_example1 fi if [ -d "chilkat_example2" ]; then rm -rf chilkat_example2 fi # also check for any previously downloaded "license.pdf" if [ -e "license.pdf" ]; then rm -f license.pdf fi # -------------------------------------------------------- # Download the chilkat_go.zip containing the Go source files that implement the Chilkat module, # which do so by calling into the Chilkat native "C" lib. curl https://chilkatdownload.com/10.0.0/chilkat_go.zip -o chilkat_go.zip if [ $? -ne 0 ]; then echo "curl download of chilkat_go.zip failed." exit 1 fi # Verify the SHA256 digest is correct. digestSha256=`sha256sum chilkat_go.zip` echo $digestSha256 if [[ $digestSha256 == *145a00b66fffd3ce5b521044c3e0ce15631ce3b1544613e5fb657134454ae24c* ]]; then echo "Good, the SHA256 digest of chilkat_go.zip is as expected." else echo "Digest of chilkat_go.zip is not the expected value." exit 1 fi # Unzip to create three subdirectories under $installDir/chilkatsoft.com: # chilkat # chilkat_example1 # chilkat_example2 unzip -q chilkat_go.zip if [ $? -ne 0 ]; then echo "unzipping chilkat_go.zip failed." exit 1 fi rm -f chilkat_go.zip # -------------------------------------------------------- echo "Let's build the Chilkat module..." echo "This can take a minute or two, or three..." CGO_LDFLAGS="-L$installDir/chilkatsoft.com/native_c_lib -lchilkatext_$machineArch -lpthread -lresolv -ldl -lstdc++" cd chilkat go mod init chilkatsoft.com/chilkat go build if [ $? -ne 0 ]; then echo "go build failed." exit 1 fi echo "Successfully built the Chilkat Go module on MacOS $machineArch."