Using SQLite with C on Windows

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

I moved sqlite3.h to the / lib path. But when I try to run the program, I get many linker errors saying "undefined reference to sqlite3_open" etc.

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

Thanks a lot!

+4
source share
5 answers

I finally understood my answer: http://source.online.free.fr/Windows_HowToCompileSQLite

The above link creates a .dll that must be placed in / bin and one .a file that must be passed as an option to the linker!

Thanks to David !!

+2
source

sqlite3.h should be in your inclusion path, and not in your library path. The library file is different; if you use Dev-Cpp, it should be called libsqlite3.a (the .lib file specified by @Ignacio for MSVC). After you put this file in the library path, you also need to instruct the compiler to link it, which should be in the compilation options for your Dev-Cpp project. You do not need sqlite3.exe at all; what if you want to query the database file manually, not programmatically.

+1
source

You do not need sqlite3.exe. You need the DLL to run it, and you need to import .lib for the link in order to create it.

0
source

SQLite documentation can be found on the home page. There is also a quick start guide .

However, before this information is useful, you need to understand how to use the compiler and linker to create a program that uses external libraries. From the question you ask, some of this is not yet clear, so perhaps the review is in order:

The compiler (which is the MinGW release of GCC from the Dev-Cpp environment distribution kit) converts the source text commonly found in. c and .h files into object files containing machine language with values ​​for some characters left unspecified. The compiler (Gnu ld is used with MinGW) receives object files from the command line, as well as from libraries (usually .a files, where the -lsqlite3 option refers to a library file called libsqlite3.a ) and collects them into a single executable file.

So, to use the SQLite library, you need header files in a place where the compiler can find them to match the #include directive. And you need an appropriate library of objects so that the linker can satisfy all the function references in the SQLite API.

One of the recommended ways to incorporate SQLite into a project is to compile it from a single-file join and link it directly to your program.Thus, you get a library that was compiled with the same compiler as the rest of your application (which reduces the likelihood of subtle run-time problems) and does not require a DLL (or .so) file in your distribution to cause problems for your users.

It is also recommended that you have a copy of sqlite3.exe . This is a useful utility that allows you to check the SQLite database file and make special changes. Just put it somewhere in your PATH so that it can be used from the command line.

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

0
source

To use the sqlite database in gcc, follow these steps ...

  • download sqlites files from here or my backup copy here (including sqlite3. h)
  • unzip the downloaded file.
  • copy to source folder (including .c file)
  • sqlite3.dll and sqlite3.h files should be with your .c files
  • The source code for the example can be found here! www (dot) tutorialspoint.com/sqlite/sqlite_c_cpp(dot) htm
  • But from the example, you should change #include to #include "sqlite3.h"
  • if your source file is test.c, then the compilation process is similar to this

    gcc -c test.c gcc -o test.exe test.o sqlite3.dll

Makefile

 test.exe: test.o sqlite3.dll gcc -o test.exe test.o sqlite3.dll test.o: test.c gcc -c test.c 

Code :: Block Settings> Compiler Settings> Linker Settings> Add> then find sqlite3.dll and add. Copy sqlite3.h to the source folder and you must change #include "sqlite3.h".

0
source

All Articles