Using SDK Dynamic Libraries
6.1. How to Use a Dynamic Library from the SDK in Your Project
Similar to Xcode, you can link your project against any dynamic library (.dylib
) provided within the Apple SDK.
Example: Using libxml2
Let's say you want to use the libxml2.dylib
library, typically found in the usr/lib
subdirectory of the SDK.
Edit
make.cmd
: Open your project'smake.cmd
file.Modify
DBE_LDFLAGS
: Add the search path and library name to theDBE_LDFLAGS
variable.-L/path/to/libs
: (Capital L) Tells the linker to look for dylibs in this directory (relative to the SDK root).-llibraryname
: (Lowercase L) Tells the linker to link against a library namedliblibraryname.dylib
. Do NOT include the "lib" prefix or the ".dylib" suffix here.
For
libxml2.dylib
located in/usr/lib
of the SDK:rem # Define here the compile options and the linker options for your project. set DBE_CPPFLAGS=-W -Wall -Wno-unused-parameter -O2 set DBE_CFLAGS= set DBE_CXXFLAGS= set DBE_LDFLAGS=-L/usr/lib -lxml2
This tells the linker to link against
/usr/lib/libxml2.dylib
.
Linking Multiple Libraries:
You can add flags for multiple libraries. For example, to link against libxml2.dylib
, libcharset.dylib
, libbz2.dylib
, and libIOKit.dylib
, all from /usr/lib
:
set DBE_LDFLAGS=-L/usr/lib -lxml2 -lcharset -lbz2 -lIOKit
Specifying Header File Locations (If Necessary): If you get #include
or #import
errors during compilation, the compiler might not be finding the header files for these libraries. You need to tell the compiler where to look for them using the -I
flag in DBE_CPPFLAGS
, DBE_CFLAGS
, or DBE_CXXFLAGS
.
For example, if libxml2
headers are in SDK_ROOT/usr/include/libxml2/
:
Code-Snippet
set DBE_CPPFLAGS=-W -Wall -O2 -I"/usr/include/libxml2"
Or, if using the full path from your Windows system (less portable, but sometimes necessary if variables aren't expanding as expected, ensure paths with spaces are quoted):
Code-Snippet
set DBE_CPPFLAGS=-W -Wall -O2 -I"C:/Users/YourUser/Darwin Build Environment/SDK/usr/include/libxml2"
Important:
-L/some/path
specifies a library search directory.-lsomelibrary
links againstlibsomelibrary.dylib
.-I/some/include/path
specifies an include header search directory.
Last updated