This Stackexchange may not be the best place for this question but I will start here.
I am trying to create a spatially-enabled, sqlite3 database. The following code is a short example of what I am trying to do.
#include <sqlite3.h>
#include <iostream>
//extern InitSpatialMetaData; // Always is an incomplete type no matter which spatialite headers I include.
int main()
{
sqlite3* db;
char* errMsg;
int rc {0};
rc = sqlite3_open_v2(":memory:", &db, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, nullptr);
rc = sqlite3_exec(db, "SELECT InitSpatialMetaData();", nullptr, 0, &errMsg);
if (rc != SQLITE_OK)
{
std::cout << "CreateSpatialMetaData error: " << errMsg << std::endl;
sqlite3_free(errMsg);
}
sqlite3_close(db);
return 0;
}
I have tried compiling with the following:
g++ example.cpp --std=c++11 -lspatialite -lsqlite3
g++ example.cpp --std=c++11 `pkg-config --libs spatialite` -lsplite3
g++ example.cpp --std=c++11 -Wl,--whole-archive -lspatialite -lsqlite3 -Wl,--no-whole-archive
Everything will compile and link. But at runtime the following error appears:
CreateSpatialMetaData error: no such function: InitSpatialMetaData
How can I include the InitSpatialMetaData
symbol? Where is this even defined?
I tried going through the spatialite_gui
source to see how this is implemented (which is not much different than mine). For Alessandro's work everything is in three files so tracking dependences is a bit difficult for me as there so much stuff in-scope.
I am building on Debian stable with supported packages:
- g++ 4.9.2
- libspatialite-dev 4.1.1
- libsqlite-dev 3.8.7.1
I am also unable to start the sqlite3 plugin at runtime, this results in an unauthorised error message.