简体   繁体   中英

c++ setting up for sqlite3

I've downloaded the source code for sqlite3 to start programming with the sqlite3 interface in c++. but I don't know how to get the .lib file for sqlite 3.

I have these files:

sqlite3.c shell.c sqlite3.h sqlite3ext.h

and this is my simple source code:

#include <stdlib.h>
#include <SQL/sqlite3.h>

using namespace std;

int main(int argc, char *argv[]){   
    sqlite3 * db;

    int rc = sqlite3_open("file.txt", &db);

}

but i get "undefined reference to sqlite3_open"

this is in my makefile:

MY_LIBS = -lsqlite3
main:
    g++ -g main.cpp -o sqliteex

which doesn't compile because there is no library named sqlite3.lib

where do I get this file or how do I build it so I can start using sqlite3?

Change your build command to

gcc -g -c sqlite3.c -o sqlite3.o
g++ -g -c main.cpp -o main.o
g++ -o sqliteex sqlite3.o main.o

(I assume sqlite3.c is the "amalgamation.")

This is their recommended way of including sqlite in your project; you compile it right in instead of linking to it.

You may (i'm not sure, you'll have to test this) need to put the sqlite include in an

extern "C" {}

block.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM