views:

124

answers:

2

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.

A: 

I'm not 100% sure this is explicitly disallowed, but another type of dynamic loading -- frameworks -- isn't supported on the iPhone. You may need to compile and link the library statically, rather than dynamically.

Colin Barrett
Thank you for your response. I actually tried to link statically initially. However, I was not able to call the sqlite3_load_extension function on the .o file. I am now trying to redesign the .c code so that the functions in the extension library are part of the same sqlite3.c code.Has anyone else called sqlite3_load_extension from within objective-c on the iPhone?
I'm pretty sure this is *not* allowed on the iPhone, because dynamically loading code requires that the file be both readable and executable, and you aren't allowed execute permissions on the iPhone. This is the same reason that `-[NSBundle load]` doesn't work.
Dave DeLong
+1  A: 

OK, I took your advice and simply added my new functionality to the sqlite3.c file I had in my project. It compiled and linked statically and works fine. Thank you for the idea. I still would like to know what was preventing me from loading an extension, but am pleased with having learned other things in solving the problem - PLUS I met my deadline. Thank you again.