ld_preload-sounds
ld_preload-sounds copied to clipboard
does this work on mac os?
There is an environment variable called DYLD_INSERT_LIBRARIES which is similar, and it is possible to do the same thing, overload libraries.
You'll need to compile a bit differently, something like gcc -Wall -o writeWav.dylib -dynamiclib writeWav.c
. Then you can do something like env DYLD_INSERT_LIBRARIES=writeWav.dylib
.
The code will probably need a little tweaking, pull requests are welcomed.
I think you'll need to set DYLD_FORCE_FLAT_NAMESPACE also.
I'll be getting a new MBP soon and I'll give this a try.
@gordol that's great! looking forward to see
Hello, neither Makefile or the command you have given out here does work. I've tried with Apple stock GCC on OSX 10.9.4, and tried Homebrew (package repository) provided GCC 4.2 and 4.9, errors as follows:
standard make
> make
gcc -pipe -std=gnu99 -fPIC -shared -Wl,--no-as-needed -ldl -o writeWav.so writeWav.c support.c
writeWav.c:69:5: warning: implicit declaration of function 'fflush_unlocked' is invalid in C99 [-Wimplicit-function-declaration]
fflush_unlocked(__wave_out);
^
writeWav.c:124:7: warning: implicit declaration of function 'fwrite_unlocked' is invalid in C99 [-Wimplicit-function-declaration]
fwrite_unlocked(&sample, sizeof(sample), 1, __wave_out);
^
2 warnings generated.
ld: unknown option: --no-as-needed
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [writeWav.so] Error 1
provided osx gcc cmdline
> gcc -Wall -o writeWav.dylib -dynamiclib writeWav.c -v
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.9.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name writeWav.c -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 241.9 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0 -Wall -fdebug-compilation-dir /tmp/ld_preload-sounds -ferror-limit 19 -fmessage-length 158 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.9.0 -fencode-extended-block-signature -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o /var/folders/3k/bcc5bhj909sg8m7p0h6fgmcr0000gn/T/writeWav-d50390.o -x c writeWav.c
clang -cc1 version 6.0 based upon LLVM 3.5svn default target x86_64-apple-darwin13.4.0
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
writeWav.c:69:5: warning: implicit declaration of function 'fflush_unlocked' is invalid in C99 [-Wimplicit-function-declaration]
fflush_unlocked(__wave_out);
^
writeWav.c:124:7: warning: implicit declaration of function 'fwrite_unlocked' is invalid in C99 [-Wimplicit-function-declaration]
fwrite_unlocked(&sample, sizeof(sample), 1, __wave_out);
^
2 warnings generated.
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -dylib -arch x86_64 -macosx_version_min 10.9.0 -o writeWav.dylib /var/folders/3k/bcc5bhj909sg8m7p0h6fgmcr0000gn/T/writeWav-d50390.o -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"___malloc_data", referenced from:
_malloc in writeWav-d50390.o
"___read_data", referenced from:
_read in writeWav-d50390.o
"___wave_out", referenced from:
_malloc in writeWav-d50390.o
_read in writeWav-d50390.o
___gen_square_wave_impl in writeWav-d50390.o
"_fflush_unlocked", referenced from:
_malloc in writeWav-d50390.o
_read in writeWav-d50390.o
"_fwrite_unlocked", referenced from:
___gen_square_wave_impl in writeWav-d50390.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Try something like this in support.h:
#ifdef __APPLE__
#define fwrite_unlocked fwrite
#define fflush_unlocked fflush
#endif
And you'll need a makefile for OSX with --no-as-needed removed.
I'll look more into this soon, since I've got a macbook now. :)
https://github.com/gordol/ld_preload-sounds/commit/bed51969a5bb75713618507fbc8e1d57a6e9515c
Looks like it's segfaulting, but that's progress.