Thursday, May 2, 2024
HomeGolang"go check" with CGO on macOS and DYLD_LIBRARY_PATH - Getting Assist

“go check” with CGO on macOS and DYLD_LIBRARY_PATH – Getting Assist


I’ve been attempting to get one among our firm’s challenge that leverages CGO and builds on Linux to construct on macOS. To that finish, I created slightly CGO Hi there World check challenge.

I can get my check challenge to construct and run executables and it respects my surroundings setting for DYLD_LIBRARY_PATH simply advantageous (since macOS System Integrity Safety will permit DYLD_LIBRARY_PATH to be inherited by non-system executables – i.e.: executables that exist in non-system places).

HOWEVER, once I run “go check” it fails to search out my native library on DYLD_LIBRARY_PATH. I attempted setting the surroundings variable CGO_LDFLAGS and that adjustments the output that I get, however it nonetheless in the end complains about not discovering the native library.

Right here is the output with out setting CGO_LDFLAGS:

% go check
# localhost/cgo2.check
/Customers/barry/dev/go/pkg/instrument/darwin_amd64/hyperlink: working clang failed: exit standing 1
ld: library not discovered for -lhello
clang: error: linker command failed with exit code 1 (use -v to see invocation)

FAIL	localhost/cgo2 [build failed]

Right here is the output after setting it:

% echo "CGO_LDFLAGS = $CGO_LDFLAGS"; go check
CGO_LDFLAGS = -L/Customers/barry/testdir/
dyld[68952]: Library not loaded: libhello.so
  Referenced from: <0F30CBC8-09BB-38FF-A929-66A67266A540> /non-public/var/folders/fl/yvgrj4p53w7blwlr0zwtf_5h0000gn/T/go-build1534663025/b001/cgo2.check
  Purpose: tried: 'libhello.so' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibhello.so' (no such file), 'libhello.so' (no such file), '/usr/native/lib/libhello.so' (no such file), '/usr/lib/libhello.so' (no such file, not in dyld cache), '/Customers/barry/testdir/chello/libhello.so' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Customers/barry/testdir/chello/libhello.so' (no such file), '/Customers/barry/testdir/chello/libhello.so' (no such file), '/usr/native/lib/libhello.so' (no such file), '/usr/lib/libhello.so' (no such file, not in dyld cache)
sign: abort entice
FAIL	localhost/cgo2	0.104s

My educated guess is that “go check” is spawning a baby course of utilizing the default system shell and that shell is not going to inherit the DYLD_LIBRARY_PATH.

Anyone else constructing/testing Go language purposes utilizing CGO on macOS and discovered how you can get it to hyperlink to dynamic libraries in non-standard places?

I might actually fairly not put all my improvement builds of my native libraries in /usr/native/lib to get this working.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments