I try to setup sqlite3 extension in a basic c++ application. I know there are still threads on this site, but I have tried all suggestions for this problem. I cannot move on, nothing was the correct solution. I want to compile the class SQLConnector.cpp (see folder structure below).
I cannot compile the application without errors.
What I have already tried:
I have already installed sqlite3 at:
C:\sqlite3\
I have downloaded sqlite-amalgamation and created a folder with the following structure:
sqlite_test
├── SQLConnector.cpp
├── shell.c
├── sqlite3.c
├── sqlite3.h
└── sqlite3ext.h
I use this command to compile the code, but it does not work:
g++ SQLConnector.cpp - l sqlite3
This is the source code of the basic code snippet:
#include "sqlite3.h"
#include "sqlite3ext.h" // I have tried it also without this file.
#include <iostream>
int main()
{
sqlite3 *db;
char *strErrorMsg = 0;
int rc;
rc = sqlite3_open("test.db", &db);
if (rc)
{
std::cout << "Can't open database " << sqlite3_errmsg(db) <<
std::endl;
return 1;
}
std::cout << "Opened database successfully!" << std::endl;
sqlite3_close(db);
return 0;
}
This is the error, I got:
SQLConnector.cpp: In Funktion »int main()«:
sqlite3ext.h:426:40: Fehler: »sqlite3_api« wurde in diesem
Gültigkeitsbereich nicht definiert
#define sqlite3_open sqlite3_api->open
^
SQLConnector.cpp:20:10: Anmerkung: bei Substitution des Makros
»sqlite3_open«
rc = sqlite3_open("test.db", &db);
^~~~~~~~~~~~
sqlite3ext.h:426:40: Anmerkung: empfohlene Alternative: »sqlite3_log«
#define sqlite3_open sqlite3_api->open
^
SQLConnector.cpp:20:10: Anmerkung: bei Substitution des Makros
»sqlite3_open«
rc = sqlite3_open("test.db", &db);
I do not know which path I should insert into the -l option. If I remove the -l option and compile sqlite3.c, then I get more than 300 errors :-D
What can I do? I do not understand how to setup the extension probably? Can someone help me and show me his setup?
I use VSCode, but I compile manually on the shell.
Aucun commentaire:
Enregistrer un commentaire