Getting started with SQLite3 using Pelles C

Here is a basic overview of our steps:

  1. Download and install Pelles C.
  2. Download SQLite3 files.
  3. Write some programs and extract some files.

By the end of this tutorial, we will have the following files:

  • run-pocc.bat: a batch script to execute the Pelles C compiler, pocc. This compiles our C source files and produces .obj (object) files.
  • run-polink.bat: a batch script to execute the Pelles C linker, polink. This produces our executable from the object files.
  • sqlite3.lib: the extracted file from sqlite3.dll, which we get using the Pelles C polib tool.
  • main.c: sample code from http://milky.manishsinha.net/2009/03/30/sqlite-with-c/
  • sqlite3.c: from the SQLite3 amalgamation file
  • sqlite3.h from the SQLite3 amalgamation file

You will put all these files into a folder somewhere. Make this folder now.

You can download Pelles C here: http://www.smorgasbordet.com/pellesc/

You will need the SQLite amalgamation file and the SQLite DLL. For our purposes, we can use the DLL that comes with Pelles C. We need the .dll file to get the .lib file. The linker needs the .lib file.

You can download SQLite here: http://www.sqlite.org/download.html

Our next step is to set up Pelles C.

  1. Install Pelles C.
  2. Set up your PATH.
  3. Test your tools.

For this tutorial, I used the 32-bit version of the Pelles C IDE. The download comes with tools in the Bin\ directory. Add an environment variable, PELLESBIN, with the value C:\Program Files\PellesC\Bin, and then add %PELLESBIN% to the end of the Path environment variable.

Open Command Prompt and type pocc. It should bring up the Pelles C compiler options.

Next, we will grab the amalgamation file from the SQLite site. Copy the C source file and header file to the folder you made. Also copy sqlite3.dll from the PellesC\ directory to your folder.

Ok, now run

> polib sqlite3.dll /OUT:sqlite3.lib

We’ll mention this .lib file to the linker with the /DEFAULTLIB option later.

Create a file main.c and copy-paste manishsinha’s code into it. This will be our sample program to test that SQLite has been successfully set up.

Execute run-pocc.bat. If there are no errors, execute run-polink.bat.

You should now have a test-sqlite.exe file that you can run from the command-line.

Now that you know how to do it “the hard way,” I leave it as an exercise to figure out how to make this work “the easy way” with the IDE.

Script links:

Advertisements