https://golang.org/cmd/cgo/ > When the cgo directives are parsed, any occurrence of the string ${SRCDIR} will be replaced by the absolute path to the directory containing the source file.
So this might be what you need. #cgo LDFLAGS: -L${SRCDIR}/. -lperson On Thursday, 30 April 2020 05:19:36 UTC+1, Dean Schulze wrote: > > I'm following a simple example > <https://www.thegoldfish.org/2019/04/using-c-libraries-from-go/> of using > cgo to call a C library function from go. Executing the binary gives > > error while loading shared libraries: libperson.so: cannot open shared > object file: No such file or director > > > Here's the relevant part from the main.go file: > > /* > #cgo LDFLAGS: -L. -lperson > #include "person.h" > */ > import "C" > > > The file libperson.so is right in the same directory with main.go and > person.h. I've also created a soft link libperson.so.0 -> libperson.so but > that doesn't have any effect. I've tried this with go run and by go build > to create a binary but both give the same error. > > Does cgo recognize the LDFLAGS: -L. symbol at all? > > What do I need to do to get a go binary to call a C function in a .so? I > really don't want to put my .so in the /usr/lib directory just to get a > static linked binary for something like this. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/77f0e481-188f-4ec8-a621-37ff6c720cfd%40googlegroups.com.