What is the exact equivalent of LD_PRELOAD on OSX?

I use LD_PRELOAD to connect the library function, and on Linux it works fine. But I can't figure out how to make an equivalent in OSX.

The setup I have on Linux is as follows:

The code:

 #include <stdio.h> #include <dlfcn.h> #include <stdlib.h> #include <unistd.h> #include <ruby.h> void rb_raise(unsigned long exc, const char *fmt, ...) { static void (*libruby_rb_raise) (unsigned long exc, const char *fmt, ...) = NULL; void * handle; char * error; if (!libruby_rb_raise) { handle = dlopen("/path/to/libruby.so", RTLD_LAZY); if (!handle) { fputs(dlerror(), stderr); exit(1); } libruby_rb_raise = dlsym(handle, "rb_raise"); if ((error = dlerror()) != NULL) { fprintf(stderr, "%s\n", error); exit(1); } } // ...code... return Qnil; } 

Who am I compiling with:

 gcc -Wall -O2 -fpic -shared -ldl -g -I/path/to/includes/ -o raise_shim.so raise_shim.c 

Then I run with:

 LD_PRELOAD=./raise_shim.so ruby 

All of this works well on Linux, what is equivalent for each step to make it work on OSX? I searched this on Google and could not get it to work with the information provided, as there is no information about some steps.

Thanks in advance!

+7
source share
1 answer

Take a look at DYLD_INSERT_LIBRARIES . This is the variable you are looking for.

See also this answer .

+9
source

All Articles