Objective-C - is a language belonging to C group languages.
In that case, I can use any C++
libraries in my iOS project, am I right?
How can I do that? Any suggestions?
Objective-C - is a language belonging to C group languages.
In that case, I can use any C++
libraries in my iOS project, am I right?
How can I do that? Any suggestions?
If you wish to integrate the source code of the library into your application, then your question is indeed a duplicate of How can I use C++ with Objective-C in XCode as mentionned by tilo
If you wish to use the built library (for instance a .so
file), you need to:
.
// 1. Load library
void *lib = dlopen("path/to/you/lib.so", RTLD_LAZY);
// 2. Handle errors (load failed)
if (!lib)
{
fprintf(stderr, "dlopen(): %s\n", dlerror());
exit(EXIT_FAILURE);
}
// 3. Get lib functions addresses
any_library_function = (void *)GetProcAddress(lib, "any_library_function");
// 4. Use the functions
any_library_function(…);
Note: You may need to rename the source file in which you use that code from .m
to .mm
. Best is to do that directly in Xcode after the file is created.
Yes, you can. Either your C++ library exposes bindings with C linkage that you can use directly in Objective-C, or you can use Objective-C++ to access the C++ bindings.