I already build sqlite3.c into my application and extension-functions.c (hxxps://www.sqlite.org/contrib) into a shared library and it worked fine, but for the project I'm working on I have to statically link sqlite3 + extension functions into a C++ application. I already read a lot of sources to this topic, but I cannot get it working.
Minimal example (test.cc):
#include "sqlite3.h"
#include<cstdlib>
void sqlite3_extension_functions_init(void);
// typedef struct sqlite3_api_routines sqlite3_api_routines;
// int sqlite3_extension_functions_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi);
int main(int argc,char *argv[]) {
// sqlite3_auto_extension( (void(*)(void))sqlite3_extension_functions_init );
sqlite3_auto_extension( sqlite3_extension_functions_init );
sqlite3 *database_;
sqlite3_open_v2("test.db", &database_, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
sqlite3_close_v2(database_);
return 0;
}
Build command:
gcc -o test sqlite3.c extension_functions.c test.cc -lpthread -lm -ldl -DSQLITE_CORE
(-DSQLITE_CORE no influence ?)
Errors:
/tmp/ccPfaDLE.o: In function `main':
test.cc:(.text+0x10): undefined reference to `sqlite3_extension_functions_init()'
collect2: ld returned 1 exit status
using commented lines instead:
/tmp/ccrs9B0K.o: In function `main':
test.cc:(.text+0x10): undefined reference to `sqlite3_extension_functions_init(sqlite3*, char**, sqlite3_api_routines const*)'
collect2: ld returned 1 exit status
- sqlite3.c, sqlite3.h, sqlite3ext.h from SQLite 3.8.6
- extension_functions.c from https://www.sqlite.org/contrib (renamed extension-functions.c) -> modified for static linking according to http://sqlite.1065341.n5.nabble.com/Example-Showing-ACTUAL-Use-of-sqlite3-auto-extension-td27657.html and renamed
int sqlite3_extension_init()
intoint sqlite3_extension_functions_init()
Other sources I used:
- hxxp://books.google.de/books?vid=ISBN1449399649&q=209
- hxxps://www.sqlite.org/loadext.html
- hxxp://stackoverflow.com/a/1295765
Maybe I'm blind, but the function prototype is given in test.cc and the function definition in extension_functions.c. Has anybody an idea what is wrong with this code example? Thank you in advance for your help.(I'm sorry for the hxxp:// links, but I'm not allowed to post more than two links)