I am trying to build a c application that uses sql.
For that I need sqlite3
header. I have already installed sql in my system and
sqlite3
in terminal gives:
SQLite version 3.36.0 2021-06-18 18:36:39 Enter ".help" for usage hints. Connected to a transient in-memory database. Use ".open FILENAME" to reopen on a persistent database. sqlite>
I have tried searching for this over web and found many relevant solutions including this.
Since I am working on Windows,
$ sudo apt-get install libsqlite3-dev
did not work. I also tried to change
#include <sqlite3.h>
to
#include "sqlite3.h"
with sqlite.h file in the same directory as my cpp code file(as I found people using it in videos). But this time I ended up with ''' C:\Users\username\AppData\Local\Temp\ccwQfHZB.o:temp.cpp:(.text 0x1e): undefined reference to `sqlite3_open' collect2.exe: error: ld returned 1 exit status '''
I am quite new to it, so any help is appreciated. Thanks.
CodePudding user response:
So you clearly need a tutorial in how to use third party libraries. That's too much to describe here. But this might get you started.
You have to tell your compiler where the header files you are including are located. Having them installed is not enough. Use the
-I
compiler option for that.You have to tell your compiler where the library files that you are linking with are located. Having them installed is not enough. Use the
-L
compiler option for that.You have to tell your compiler the names of the libraries that you are linking with. Having them installed is not enough. Use the
-l
compiler option for that.
All these options may need to be given multiple times depending on your precise setup and the libraries you are using.
Sorry but I don't know what the sqlite libraries are called, and obviously I don't know where you installed stuff.
Moving header files around is never the right solution, and any video you saw that does that doesn't know what they are talking about. Install stuff where you think is best and then tell your compiler where that is. Any sqlite tutorial that uses the g compiler should go through this process in more detail, but there are a lot of bad C tutorials out there.
CodePudding user response:
I found the solution to this problem:
- included two files(*): sqlite3.0, sqlite3.h in same folder as my main code.
- added #include "sqlite3.h"
- compiled using the command: g sqlite3.o main.cpp -o main
This finally resolved my error. *(these were downloaded from sqlite.org)