How Can I Use Sqlite3.c In A C++ Project?
Solution 1:
Have you try in this way? (with double pointer):
intmain() {
sqlite3* db;
constchar* dbname = "test.db";
sqlite3_open(dbname, &db);
return0;
}
I suppose you're working on linux. Another approach is to execute a script:
intmain() {
system("connectDB.sh");
/* connectDB.sh should be chmod +x */
}
Your file connectDB will be:
#!/bin/bash
sqlite3 test.db "select * from test.table"
Solution 2:
SQLite is written in C, and there are a number of differences between C and C++. Not huge numbers, but they're definitely not the same and neither is a superset of the other. Because you are using a single Eclipse project, you've probably ended up trying to compile C code with a C++ compiler, and are therefore coming unstuck on these small differences.
You are advised to build sqlite3.c into a separate library (it can be a static library or a dynamic one; your call) as a C project, and then make your C++ project just use that C project as a dependency. Or you can build it once and just have it as an external dependency; that'll work too. (To be fair, it's an external dependency; you shouldn't really embed it wholesale into your code anyway as that will make tracking bugfixes harder. Keeping it separate — at least for build, even if not for distribution — will make your life much easier.)
Post a Comment for "How Can I Use Sqlite3.c In A C++ Project?"