Compiling SQLite with Dev-C++

Hello everyone,

This is my first post. I am trying to manually compile SQLite 3.6.23 with Dev-C++ as a static library (I can always just download de DevPac, which comes precompiled, but I want to learn to do this by myself). I'm not sure which source code files I need to add to my project in order to compile it.

The amalgamation package includes:
sqlite3.def
sqlite3.h
sqlite3.c
sqlite3ext.h
shell.c

I read somewhere, that shell.c is not required. When I add the other files to my project, I get the following errors:
1
2
C:\Dev-Cpp\Projects\libsqlite3\sqlite3.c In function `void strftimeFunc (sqlite3_context*, int, sqlite3_value**)': 
12281 C:\Dev-Cpp\Projects\libsqlite3\sqlite3.c invalid conversion from `void*' to `char*'  


and many other similar errors. When I remove this file, sqlite3.c it seems to compile, as all I get is a message "creating libsqlite3.a".

My questions:
1. Can I use the libsqlite3.a I generated without the sqlite3.c file? Is it complete?
2. How do I add it to my programs?
3. Can I use the available precompiled dll (available from sqlite.org) instead? How would I do this?

Any info will be greatly appreciated.
Why would you generate a static library? In the case of SQLite it's far, FAR easier to just add the C source to the project. Doing anything else is an unnecessary complication.
Last edited on
But, which source files do I add? sqlite3.c always fails to compile with the error I mentioned above. If it's not included, a simple program such as this fails to compile:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <cstdlib>
#include <iostream>
#include "sqlite3.h"

using namespace std;

int main(int argc, char *argv[])
{
    sqlite3 *db ;
    sqlite3_open( "test.db", &db);
    system("PAUSE");
    return EXIT_SUCCESS;
}


with linker error:

[Linker error] undefined reference to `sqlite3_open'

If I include sqlite3.c, I get the error above. Please help!
You're not supposed to #include the C source. You're supposed to add it to the project. Right click on the project in the project explorer (or whatever it's called in Dev-C++. It's a treeview that lists the project and all the sources in it) and select "add files" or something, then choose sqlite3.c. This will compile the source into the final executable and get rid of that linker error you're getting.
I did that. I added the sources to the project using Dev-C++'s "Add to project" option. I also did that a test: I created a new project with a clean main program

1
2
3
4
5
6
7
8
9
10
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    system("PAUSE");
    return EXIT_SUCCESS;
}


I added the Sqlite3 amalgamation sources to my project via "Add to Project". I compiled, and got the following (I'm including the full compile log now):

1
2
3
4
5
6
7
8
9
10
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Projects\sqlite_test\Makefile.win"
Executing  make...
make.exe -f "C:\Dev-Cpp\Projects\sqlite_test\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"C:/Dev-Cpp/include/c++/3.4.2/backward"  -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"C:/Dev-Cpp/include/c++/3.4.2"  -I"C:/Dev-Cpp/include"   

g++.exe -c "../../../Documents and Settings/melissa/My Documents/programas/sqlite-amalgamation-3_6_23_1/sqlite3.c" -o "../../../Documents and Settings/melissa/My Documents/programas/sqlite-amalgamation-3_6_23_1/sqlite3.o" -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"C:/Dev-Cpp/include/c++/3.4.2/backward"  -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"C:/Dev-Cpp/include/c++/3.4.2"  -I"C:/Dev-Cpp/include"   
 ...

Execution terminated


Had to cut the list because it was too long.

Perhaps there is some prerequisite library I am missing, or maybe the MinGW version included with Dev-Cpp is lacking something that's required for compilation?
Hi,

I seem to have solved it. It seems it must be compiled with gcc, rather than g++. I guess the need for a static library is so it can be used in g++ based projects.
There should be no difference. g++ is supposed to call gcc if passed a C source.
SQLite Amalgamation and g++

"This is not a link issue, but a compiler one. SQLite is ANSI C, so you
should compile it with gcc. It will still be usable within your C++
library/project, as sqlite3.h qualifies all functions extern "C"."


http://www.mail-archive.com/sqlite-users@sqlite.org/msg30132.html
Topic archived. No new replies allowed.