how to make a wrapper from .dylib to objective-C

I have created three dynamic libs in .dylib for MACOSX. It's mainly C/C++ code coming from linux ported to MAC to create an app.

I have added these 3 libs to my Xcode project and modify the build phase settings to link them at build/run time to the binary.

I have seen the API belows:

dlopen() dlsym()...

using these APIs I can load my dylib but I'm not sure that I'm doing it the right way. What I need to do is to create an app for OS X which use the dylib to access to some features to control a device through USB. One of the lib content is the MTP lib.

I'm not sure if I need to use dlopen() as the lib is already declared in the build phase settings.

I do not really know how to make it easy to access to all APIs in these libraries. Do I need to create (.m/.h file) which link the API C/C++ functions from my dylib to Objective-C functions to make it easier to use. It make more sens for me to do it because it would be more clear.

If yes, do someone as an example on how to do this "wrapper", how the .m / .h is able to link and connect to the dylib. After I would just need to use for example a include of the .h in the main.m to access to the function from the dylib.

Thanks for your help

Sebastien

MacBook, OS X Mavericks (10.9.5)

Posted on Oct 7, 2014 2:10 PM

Reply
2 replies

Oct 7, 2014 9:56 PM in response to sebfromirvine

If you have the library, then you should also have (and need) the .h files for the library. Both the library and the .h files have to be in a path that the compiler/linker 'knows'. Once they are, then it is easy to access all the APIs by simply adding an import .h (or include) directive to the class that you are building.


dlopen() and dlsym() are for accessing and linking executables with libraries from within your application while it is running, which is not what you are trying to do.


You include (or better, import) the .h at the top of the .h of the class that needs to use the library.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

how to make a wrapper from .dylib to objective-C

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.