airbusgeo / godal

golang wrapper for github.com/OSGEO/gdal
Apache License 2.0
137 stars 27 forks source link

Error locating libgdal.dylib in macos #98

Open ashnair1 opened 2 years ago

ashnair1 commented 2 years ago

I was trying out the godal library (on my M1 Mac) and wrote a simple script as follows:

package main

import (
    "github.com/airbusgeo/godal"
)

func main() {
    godal.RegisterAll()
}

Running go run main.go throws the following error

dyld[19569]: Library not loaded: @rpath/libgdal.30.dylib
  Referenced from: /private/var/folders/y5/yh59dj093xn_dz8lm0mhv6lh0000gp/T/go-build1573968352/b001/exe/test
  Reason: tried: '/usr/local/lib/libgdal.30.dylib' (no such file), '/usr/lib/libgdal.30.dylib' (no such file)
signal: abort trap

godal has a dependency on gdal and I had installed it via conda. Due to this, the dylib is located under my conda folder - /Users/ash/miniconda3/lib not /usr/local/lib.

How can I have the program search for libgdal.dylib in /Users/ash/miniconda3/lib instead of /usr/local/lib ?

Had raised this question in StackOverflow previously but didn't get any solutions to this issue. Link - here

eval-apply commented 2 years ago

godal makes use of pkg-config to pass ldflags to cgo, so you will need to let it know where the GDAL pkg-config path is. I don't know the specific install location when using miniconda, but once you know the path something like this would work:

PKG_CONFIG_PATH=//Users/ash/miniconda3/lib/gdal/pkgconfig go run main.go

ashnair1 commented 2 years ago

I had already set PKG_CONFIG_PATH prior to running the command. The error still occurs.

$ echo $PKG_CONFIG_PATH
/Users/ash/miniconda3/lib/pkgconfig

$ ls $PKG_CONFIG_PATH | grep gdal.pc
gdal.pc

$ go run main.go
dyld[28793]: Library not loaded: @rpath/libgdal.30.dylib
  Referenced from: /private/var/folders/y5/yh59dj093xn_dz8lm0mhv6lh0000gp/T/go-build3191999631/b001/exe/test
  Reason: tried: '/usr/local/lib/libgdal.30.dylib' (no such file), '/usr/lib/libgdal.30.dylib' (no such file)
signal: abort trap
eval-apply commented 2 years ago

ok then you'd need to tell it where to find the dynamic library at runtime, something like LD_LIBRARY_PATH=/Users/ash/miniconda3/lib go run main.go perhaps? I'm just guessing that's where miniconda libs live.

ashnair1 commented 2 years ago

You mean DYLD_LIBRARY_PATH? This is for MacOS. I tried setting those and the problem persists.

Btw, that is indeed where miniconda libs live