On Thu, Apr 30, 2020 at 10:06 AM <m...@pekim.co.uk> wrote:
>
> 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 Unix systems, the -L option sets the search path for the shared
library at link time.  It does not set the search path for the shared
library at run time.  You can set the run time search path using the
-R option.  See the system linker docs.

Ian



> On Thursday, 30 April 2020 05:19:36 UTC+1, Dean Schulze wrote:
>>
>> I'm following a simple example 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.

-- 
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/CAOyqgcUSRrk1VQJiJC%2BJVa8O%3DY%2Btco9HszP%2BO%2BBnPnU0bhCf%2Bg%40mail.gmail.com.

Reply via email to