Author Topic: Setting up SQLite  (Read 10122 times)

Offline bugmenot

  • Multiple posting newcomer
  • *
  • Posts: 32
Setting up SQLite
« on: February 16, 2009, 05:19:19 pm »
Hi, i have some questions about setting up sqlite.

  • I've downloaded sqlite-amalgamation-3_6_10.zip and tried to compile a static library with it. So i started a new Project ("Static Library") and added all the files included in the zip-file (sqlite3.c,  sqlite3.h, sqlite3ext.h). But all i got was sqlite3.o
  • I can't add a .o-file to the linker settings
  • How can i get it work?
  • Does it works with the .dll? How can i use it?

please help

thanks

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Setting up SQLite
« Reply #1 on: February 16, 2009, 05:37:30 pm »
I just downloaded the sources, put them into the wizard-created project, and get a "*.a" file in the projects root-dir.

If you don't have it, your toolchain might be broken (missing ar.exe).

Offline bugmenot

  • Multiple posting newcomer
  • *
  • Posts: 32
Re: Setting up SQLite
« Reply #2 on: February 16, 2009, 06:52:32 pm »
oh sry... yes there is also a ".a"  :oops:

Now i get on "Settings -> Compiler and Debugger... -> Linker settings" and "Project -> Build options... -> Linker settings" and add this file there right? Cause this doesn't work yet.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Setting up SQLite
« Reply #3 on: February 17, 2009, 12:38:04 am »
oh sry... yes there is also a ".a"  :oops:

Now i get on "Settings -> Compiler and Debugger... -> Linker settings" and "Project -> Build options... -> Linker settings" and add this file there right? Cause this doesn't work yet.


Normally you should not touch "Settings -> Compiler and Debugger... -> Linker settings", because the settings you make there are global to all projects, build with the compiler you have chosen.

The second is correct and should work. You can either use the absolute path here, or make sure the linker searchpath is set correctly. You can also youse the shortname of the lib (if serachpath is okay): if the library is called libsqlite.a it should be enough to use sqlite here.

You will of course need to include the header-files, to make the functions known to your sources.

Offline Alfykun

  • Single posting newcomer
  • *
  • Posts: 3
Re: Setting up SQLite
« Reply #4 on: October 31, 2011, 01:59:23 pm »
I too am having the same issue,

I got the sqlite amalgamation zip and i tried to compile it to get the libsqlite3.a file but its just not happening..

can you please give me all the steps .. [complete noob]

I created a new project added the .c &.h files and tried to compile and it gives me this error

"undefined reference to 'Win Main@16'"


please help.


zabzonk

  • Guest
Re: Setting up SQLite
« Reply #5 on: October 31, 2011, 02:16:20 pm »
> "undefined reference to 'Win Main@16'"


That's the message you get if you created a windows GUI project - you want a static library.

Offline Alfykun

  • Single posting newcomer
  • *
  • Posts: 3
Re: Setting up SQLite
« Reply #6 on: October 31, 2011, 02:26:25 pm »
Ohkay what do i do?

where can I change that?

zabzonk

  • Guest
Re: Setting up SQLite
« Reply #7 on: October 31, 2011, 02:36:50 pm »
> where can I change that?

When you first start CB, you get an option to create a new project - select that and then choose "Static Library" from the resulting dialog.


Offline Alfykun

  • Single posting newcomer
  • *
  • Posts: 3
Re: Setting up SQLite
« Reply #8 on: October 31, 2011, 02:57:51 pm »
managed to make complie :) thanks

got a .a file which i renamed to libsqlite2.a and placed it into the lib folder and the .h file to the include folder.

tried to complie a simple connectivity program

Code
#include<stdio.h>
#include<sqlite3.h>
#include<stdlib.h>

int main(int argc, char** args)
{
    // Create an int variable for storing the return code for each call
    int retval;

    // The number of queries to be handled,size of each query and pointer
    int q_cnt = 5,q_size = 150,ind = 0;
    char **queries = malloc(sizeof(char) * q_cnt * q_size);

    // A prepered statement for fetching tables
    sqlite3_stmt *stmt;

    // Create a handle for database connection, create a pointer to sqlite3
    sqlite3 *handle;

    // try to create the database. If it doesnt exist, it would be created
    // pass a pointer to the pointer to sqlite3, in short sqlite3**
    retval = sqlite3_open("sampledb.sqlite3",&handle);
    // If connection failed, handle returns NULL
    if(retval)
    {
        printf("Database connection failed\n");
        return -1;
    }
    printf("Connection successful\n");

    return 0;
    }


but i am getting this error now  :? "undefined reference to "sqlite3_open"

zabzonk

  • Guest
Re: Setting up SQLite
« Reply #9 on: October 31, 2011, 03:49:45 pm »
I don't know what you mean by the lib and include folders - it's best not to add anything to CB's own directories. Still, you need to:

 - create a console application project
 - write your main function
 - from Project Build Options dialog add the directory containing the sqlite3.h header file to the "search directories" tab
 - from Linker settings in the same dialog, use the add button to add the full name and path of your .a library file