Saturday, 18 February 2017

sqlite - HOW TO sqlite3_load_extension from within Objective-c [error: dlopen(...) image not found]

I am trying to load an extension to sqlite3 for use within iPhone application objective-c code. I successfully compiled the c file of new functions into a dylib named libsqlitefunctions.dylib. Here is where I am a bit lost. I call sqlite3_load_extension as follows:



char *error = sqlite3_malloc(MAX_SQLITE_ERROR_MESSAGE_SIZE);
const char *library = [@"libsqlitefunctions.dylib" UTF8String];



if (sqlite3_load_extension(database, library, 0, &error) != SQLITE_OK) {
message = [NSString stringWithFormat:@"%s", error];
}




sqlite3_free(error);



No matter what I do, I get the error: dlopen(libsqlitefunctions.dylib, 10): image not found



I tried:




  1. indicating the fully qualified path to the dylib

  2. indicating a relative path


  3. not indicating a path (as shown above)

  4. adding the dylib as a framework

  5. adding the .c file to my project and compiling it into a .o file and then trying to load it



Please note that this is not an entry point problem, since I pass 0 as that arg. This will force the dylib to load by calling an init function defined in the dylib. I do not even get to that point.



I am pretty much a newbie compared to the rest of you guys and feel that I am probably lacking an understanding of how libraries are loaded.



I would really appreciate any ideas since the ability to make use of the functions in this library is important to the functionality of my app. Thank you all in advance.

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...