digitalmars.D.learn - Linking to Dynamic Library on Mac OS X
- TJB (17/17) May 14 2015 I have built a toy dynamic shared library on Mac OS X (in C), and
- John Colvin (2/19) May 15 2015 Off the top of my head: does adding -L-L$(pwd) help?
- TJB (6/7) May 15 2015 This is what I get:
- John Colvin (11/19) May 15 2015 should be
- Jacob Carlborg (4/7) May 16 2015 That should not be necessary.
- TJB (2/17) May 16 2015 This works perfectly. A big thanks!
I have built a toy dynamic shared library on Mac OS X (in C), and I have verified that it works from C. Now I would like to call it from D. So I have created the following interface file: $ cat hello.di extern (C): void printHelloWorld(); which I try to compile and run. But I get the following error: $ dmd main.d -L-lhello ld: library not found for -lhello clang: error: linker command failed with exit code 1 (use -v to see invocation) --- errorlevel 1 I gather that mac os x doesn't know where to find libhello.dylib (it is in the current directory). So how do I pass that information? Thanks! TJB
May 14 2015
On Friday, 15 May 2015 at 03:33:47 UTC, TJB wrote:I have built a toy dynamic shared library on Mac OS X (in C), and I have verified that it works from C. Now I would like to call it from D. So I have created the following interface file: $ cat hello.di extern (C): void printHelloWorld(); which I try to compile and run. But I get the following error: $ dmd main.d -L-lhello ld: library not found for -lhello clang: error: linker command failed with exit code 1 (use -v to see invocation) --- errorlevel 1 I gather that mac os x doesn't know where to find libhello.dylib (it is in the current directory). So how do I pass that information? Thanks! TJBOff the top of my head: does adding -L-L$(pwd) help?
May 15 2015
Off the top of my head: does adding -L-L$(pwd) help?This is what I get: $ dmd main.d -L-L$(pwd) -lhello Error: unrecognized switch '-lhello' Sorry if this is completely elementary and I am being quite dumb. Thanks, TJB
May 15 2015
On Friday, 15 May 2015 at 19:39:53 UTC, TJB wrote:should be $ dmd main.d -L-L$(pwd) -L-lhello The -L means "send the following argument to the linker". Note that you may also find you need to help OS X find the dylib when running the program, either by moving it to one of the system locations or using DYLD_LIBRARY_PATH or DYLD_FALLBACK_LIBRARY_PATH (see http://stackoverflow.com/questions/3146274/is-it-ok-to-use-dyld-library-path-on-mac-os-x-and-whats-the dynamic-library-s). However, I think the runtime linker looks in the present directory by default, so you might get away with it.Off the top of my head: does adding -L-L$(pwd) help?This is what I get: $ dmd main.d -L-L$(pwd) -lhello Error: unrecognized switch '-lhello' Sorry if this is completely elementary and I am being quite dumb. Thanks, TJB
May 15 2015
On 2015-05-15 21:49, John Colvin wrote:Note that you may also find you need to help OS X find the dylib when running the program, either by moving it to one of the system locations or using DYLD_LIBRARY_PATH or DYLD_FALLBACK_LIBRARY_PATHThat should not be necessary. -- /Jacob Carlborg
May 16 2015
On Friday, 15 May 2015 at 19:49:30 UTC, John Colvin wrote:On Friday, 15 May 2015 at 19:39:53 UTC, TJB wrote:This works perfectly. A big thanks!should be $ dmd main.d -L-L$(pwd) -L-lhelloOff the top of my head: does adding -L-L$(pwd) help?This is what I get: $ dmd main.d -L-L$(pwd) -lhello Error: unrecognized switch '-lhello' Sorry if this is completely elementary and I am being quite dumb. Thanks, TJB
May 16 2015