Why is there no LoadLibrary for dylib?

Go has the function LoadSystemLibrary inside the /x/sys/windows package which eventually calls the function in the syscall package. This allows the programmer to dynamically call functions in DLL files on a windows machine from Go. Although, MacOS does contain dynamic libraries suffixed with .dylib there is no equivalent function for loading these files.

Why does none exist? Is it because no one has taken the time to write it or is it just impossible? If it is possible, are there any implementations (in any language) that I can reference to code a Go version?

I’ve done a lot of research and found this page which explains how to read in a Mach-O file (another name for dylibs). Is there a way that I can call the functions after they’ve been loaded? I also thought perhaps I create a VM to interpret the files.

EDIT:
I just came across this godoc that can open and read Mach-O files. But this still doesn’t explain how to actually do the calling of the functions which is my main purpose.

See https://github.com/golang/go/issues/18296. There’s a POC to make it work here: https://github.com/notti/nocgo/

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.