Skip to content

dyld: Library not loaded: libdb2.dylib when running GO ibm_DB sdk in MAC #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sanjeevghimire opened this issue Jun 19, 2019 · 8 comments

Comments

@sanjeevghimire
Copy link

when running the code snippet I get this error:

I installed the driver as per the instruction in the readme. the lib folder has the file libdb2.dylib but it complains about it:

  Referenced from: /var/folders/_h/4trwzcd908g703_vdw2q1yn00000gn/T/go-
build774492263/b001/exe/db2conn
  Reason: image not found
signal: abort trap```

the code I am using is:

package main

import (
_ "github.com/ibmdb/go_ibm_db"
"database/sql"
"fmt"
)

func main(){
con:="HOSTNAME=host;DATABASE=db;PORT=50000;UID=u;PWD=pwd"
db, err:=sql.Open("go_ibm_db", con)
if err != nil{

	fmt.Println(err)
}
db.Close()

}


@sanjeevghimire sanjeevghimire changed the title dyld: Library not loaded: libdb2.dylib dyld: Library not loaded: libdb2.dylib when running GO ibm_DB sdk in MAC Jun 19, 2019
@sanjeevghimire
Copy link
Author

Figured out the problem. My path was pointing to wrong DYLD library.

@bombsimon
Copy link

@akhilravuri1 I still cannot get this to work. I installed the driver with setup.go. The solution in this issue and #50 and #47 and #29 all seem to be resolved with the correct environment. Any help would be appreciated!

This is my environemnt:

$ for env in $DB2HOME $CGO_CFLAGS $CGO_LDFLAGS $DYLD_LIBRARY_PATH; do echo $env; done
/Users/simon/tmp/db2test/clidriver
-I/Users/simon/tmp/db2test/clidriver/include
-L/Users/simon/tmp/db2test/clidriver/lib
/Users/simon/tmp/db2test/clidriver/lib

When trying to use the driver, I get the error form this issue:

$ go run main.go
dyld: Library not loaded: libdb2.dylib
  Referenced from: /var/folders/q3/bf76j42160j2nt4s2tz1_fd40000gn/T/go-build982956092/b001/exe/main
  Reason: image not found
signal: abort trap

However, the file mentioned seems to be present according to me:

$ stat -f "%N (%z)" $DYLD_LIBRARY_PATH/libdb2.dylib
/Users/simon/tmp/db2test/clidriver/lib/libdb2.dylib (32902420)

What am I missing here? Why does it seem like I'm missing the library when trying to use the driver?

@bombsimon
Copy link

Ok this was new to me. Don't know what this is or why but it seems like this only occurs with go run (and the executable is being ran from a temp folder). If I compile the program first it works as expected.

$ go run main.go; echo $?                                                                                                                                                                                                                                                                                                 
dyld: Library not loaded: libdb2.dylib
  Referenced from: /var/folders/q3/bf76j42160j2nt4s2tz1_fd40000gn/T/go-build556855419/b001/exe/main
  Reason: image not found
signal: abort trap
1
$ go build main.go && ./main; echo $?
0

Is this because the driver requires a relative path? It sounds odd because libdb2.dylib isn't relative to main.go but that's the only guess I have. 🤔

@kierquebs
Copy link

Try this one

instead of:
go run main.go

I used:
go build -v

then to your command line
./project_name

@akhilravuri1
Copy link
Contributor

Hi @bombsimon

please provide your mac version and go version.

Thanks,
Akhil

@bombsimon
Copy link

@kierquebs Thanks! Like I wrote in my last post in March it's working if I first build the binary and then run it so the question is why that is.

@akhilravuri1 I'm running macOS Catalina 10.15.4 with go version go1.14 darwin/amd64.

This is no major issue but I was just curious why it's possible to build and execute but not perform go run.

@robherley
Copy link

Hey I know this issue is kinda old but @bombsimon to answer your question or anyone else who finds this, the reason is here: golang/go#36572

As for the workaround, you can just use go run -exec like so:

go run -exec "env DYLD_LIBRARY_PATH=path/to/your/lib" main.go

@htdinh13
Copy link

Beside the workaround with go run -exec, do we have permanent fix for that issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants