How can I link executable with dylib in Mac OS X command line?
You are dynamically linking libraries to compile your code, which needs to tell the system where to find the libraries both compile time and run time.
Right now, you are only telling the compiler to compile from libraries in the path specified by -L, but not telling the system where to find the libraries when executing it.
You probably need this:
export DYLD_LIBRARY_PATH=./lib:$DYLD_LIBRARY_PATH
where ./lib
indicates where your libraries are.
Include a dylib into an OS X Framework
I found a solution :
As every dylib, we have to use install-name-tool to specify the install-paths.
We also have to codesign the framework and the contained dylib with our developer ID.
GCC: Linking a dylib on Mac Os
Add -lmemcached
at the very end when compiling.
How to create a .dylib C extension on mac os x with distutils and/or setuptools?
Here's what worked for me (added lines in my setup.py
):
if sys.platform == 'darwin':
from distutils import sysconfig
vars = sysconfig.get_config_vars()
vars['LDSHARED'] = vars['LDSHARED'].replace('-bundle', '-dynamiclib')
This configuration seems to be hard-wired in the module _sysconfigdata
. It's also overridable using environment variables, so this works as well:
LDSHARED="cc -dynamiclib -undefined dynamic_lookup -arch x86_64 -arch i386 -Wl,-F." python setup.py install
MAC OSX dylib's and how to use them
As moshbear commented above, dylib
files are how shared libraries are packaged on Mac OS X. To use such a shared library, you need to pass two switches to your compiler, -L
and -l
. The first adds the directory containing your dylib
to the linker's library search path, and the second specifies the library to link against. Something like this, for a fictional libfoo.dylib
that lives in /usr/mylibs
:
clang code.c -L/usr/mylibs -lfoo
Related Topics
Why Sizeof Int Is Wrong, While Sizeof(Int) Is Right
Cc1Plus: Error: Unrecognized Command Line Option "-Std=C++11" with G++
Stepping into Qt Sources in Qt Creator (In Ubuntu Linux)
Shared_From_This Causing Bad_Weak_Ptr
Return Statement in Ternary Operator C++
Read Word by Word from File in C++
When to Use Vectors and When to Use Arrays in C++
Linux Optimistic Malloc: Will New Always Throw When Out of Memory
Should I Use Public or Private Variables
Std::Lexical_Cast - Is There Such a Thing
How to Check That the Passed Iterator Is a Random Access Iterator
How to Extend a Lexical Cast to Support Enumerated Types
Is There a C++ Iterator That Can Iterate Over a File Line by Line