tags:

views:

34

answers:

4

Hi all !

I am trying to develop a project in C (on Dev-Cpp IDE) using SQLite for data storage, on Windows Vista. I am trying to run this code : Sqlite with C

I moved sqlite3.h in the /lib path. But when I am trying to run the program, I get lots of linker errors, saying "undefined reference to sqlite3_open" ,etc.

Google gives me Linux commands, which cant be used here :( Can somone please guide me through the whole process of using sqlite with C , I am very new to such things. Where do I put the sqlite3.exe ??

Thanks a lot !!

A: 

You don't need sqlite3.exe. You need the DLL to run it, and you need the import .lib to link against in order to build it.

Ignacio Vazquez-Abrams
+1  A: 

sqlite3.h should be in your include path, not your library path. The library file is a different one; if you're using Dev-Cpp it should be called libsqlite3.a (the .lib file mentioned by @Ignacio is for MSVC). Once you've put that file in the library path, you also need to instruct the compiler to link against it, which should be in the compile options for your Dev-Cpp project. You don't need sqlite3.exe at all; that's for when you want to query the database file manually rather than programmatically.

David
@David : I have put the sqlite3.h in the include path now. Still I am getting the linker errors. Where can I get libsqlite3.a , its not in the downloaded source ? And what do we put in the compiler path. Please explain, I think I am damn too ignorant :(
Raj
Please provide me a way to get libsqlite3.a - I am not getting the download link anywhere.
Raj
A: 

I finally figured out my answer through : http://source.online.free.fr/Windows_HowToCompileSQLite

The above link creates a .dll which has to be put in the /bin, and one .a file which has to be passed as an option to the linker !

Thanks David !!

Raj
A: 

Documentation on SQLite can be had at the project's home page. There is a quick start guide as well.

However, before that information is useful, you need to understand how to use your compiler and linker to build a program that uses external libraries. From the question you are asking, some of this isn't yet clear, so perhaps a review is in order:

The compiler (which is the MinGW release of GCC from the Dev-Cpp IDE distribution) converts source text conventionally found in .c and .h files into object files which contain machine language with values for some symbols left unspecified. The linker (Gnu's ld is used with MinGW) takes object files from its command line as well as from libraries (generally .a files, where the option -lsqlite3 would refer to the library file named libsqlite3.a) and collects them in to a single executable.

So, in order to use the SQLite library, you need its header files in a place where the compiler can located them to satisfy a #include directive. And you need the matching object library so the linker can satisfy all references to functions in the SQLite API.

One recommended way to include SQLite in a project is to compile it from the single-file amalgamation, and link it directly to your program. By doing it this way, you get a library that was compiled with the same compiler as the rest of your application (which reduces the chance of subtle problems at run time) and don't need to have a DLL (or .so) file in your distribution to cause issues for your users.

It is also recommended that you have a copy of the sqlite3.exe utility available. This is a useful utility that lets you inspect a SQLite database file and make ad-hoc changes. Just put it somewhere in your PATH so that it can be used from a command prompt.

If you must use a pre-build DLL, then one is available from the SQLite project. It happens to be compiled in a way that is compatible with MinGW. Specifically, it uses the same C runtime library used by MinGW. Note that it might not be completely compatible if you were using Visual Studio or another compiler for Windows.

RBerteig