Im sorry for the bad title. I want to get started using sqlite with c++. So i downloaded the amalgamation from the site and compiled to get the .dll
gcc -shared sqlite3.c -o sqlite3.dll
I included the sqlite.h file in my project and the .dll file too. I compiled:
g++ prueba.cpp
and got this error message
C:\Users\PABLOS~1\AppData\Local\Temp\ccUI3YAt.o:prueba.cpp:(.text+0x2d): undefined reference to `sqlite3_open'
C:\Users\PABLOS~1\AppData\Local\Temp\ccUI3YAt.o:prueba.cpp:(.text+0x41): undefined reference to `sqlite3_errmsg'
collect2.exe: error: ld returned 1 exit status
Ok I said, lets see in stack overflow. In some question that I read they recomended to do this:
g++ main.cpp sqlite3.c
But the output was a really long list of error messages. I kept on reading but most of the questions where solved by:
sudo apt install libsqlite3-dev
or
gcc main.c -lsqlite3
In one of the questions the same guy that asked answered that he didnt include the .a file. So i googled about it and followed the instructions in this article. I created the .def file:
dlltool -z sqlite3.def --export-all-symbols sqlite3.dll
And created the .a file
dlltool -d sqlite3.def -l libsqlite3dll.a
Then included it in C:\MinGW\lib and tried again to compile
g++ prueba.cpp -lsqlite3dll
And i got the same error message. At this point im kind of lost (Im new to programing), and i dont know what to do next. Can you give me a pointer in the direction I should head in?
Edit: Answered a question form the coments
// This is my code
#include <iostream>
#include "sqlite3.h"
int main(int argc, char **argv) {
// Esto es lo que necesitamos para abrir la base de datos
sqlite3 *db;
char *zErrMsg = NULL;
int rc;
// La abrimos y revisamos por errores
rc = sqlite3_open("test.db", &db);
if (rc) {
std::cerr << "No se pudo abrir la base de datos: " << sqlite3_errmsg(db);
return 1;
}
std::cout << "Se pudo abrir la base de datos!"<< std::endl;
std::cin.get();
return 0;
}