GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 15-Aug-2006, 09:25
ryver ryver is offline
New Member
 
Join Date: Aug 2006
Posts: 13
ryver is on a distinguished road

linker errors while compiling sqlite3 with a program


I made this program:

CPP / C++ / C Code:
#include <stdio.h>
#include <stdlib.h>
#include "sqlite3.h"


int exe(const char* s_exe) {
    int test;
    char **result; /* where the reuslts are written to*/
    sqlite3 *db;
    char *zErrMsg;
    
    int rc;
    int nrow,ncol;
    int db_open;
    
    
    
    test = sqlite3_open("test.db", &db);
    if( test != SQLITE_OK ){
    fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    }
    rc = sqlite3_get_table(
		db,              /* An open database */
		s_exe,       /* SQL to be executed */
		&result,       /* Result written to a char *[]  that this points to */
		&nrow,             /* Number of result rows written here */
		&ncol,          /* Number of result columns written here */
		&zErrMsg          /* Error msg written here */
		);

    char *titles[ncol];
    char *data[nrow*ncol];

    if( rc == SQLITE_OK ){
        for(int i=0; i < ncol; ++i)
             titles[i]= result[i];   /* First row heading */
        for(int i=0; i < ncol*nrow; ++i)
            data[i]=result[ncol + i];
    }
    else 
        printf ("%s \n", "Fout met uitvoer data");
    sqlite3_free_table(result);
    return rc;

}



int main(){

    exe("select * from table1");

    return 0;
    }
and when I compile this I get these messages:
Code:
[Linker error] undefined reference to `sqlite3GetToken(unsigned char const*, int*)' [Linker error] undefined reference to `sqlite3MPrintf(char const*, ...)' ...And a whole lot more of the same...

It's probally an progamming mistake I made, but I can't figure out where I made it.

Any help is much appreciated.

Ryver
  #2  
Old 15-Aug-2006, 09:41
cable_guy_67's Avatar
cable_guy_67 cable_guy_67 is offline
Senior Member
 
Join Date: Oct 2004
Location: Nescopeck, PA
Posts: 1,109
cable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the rough

Re: linker errors while compiling sqlite3 with a program


It looks like you need to link to the library.

From the command line it will look something like -lsqlite or if you are using an IDE you will need to add them to your list of libraries to link to.

Mark

EDIT:
This link may help as it directs to a few examples here.
http://www.gidforums.com/showthread.php?p=47766
__________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work."
--Thomas Alva Edison
"Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety."
--Benjamin Franklin
"A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes."
--Hugh Downs
  #3  
Old 16-Aug-2006, 01:49
ryver ryver is offline
New Member
 
Join Date: Aug 2006
Posts: 13
ryver is on a distinguished road

Re: linker errors while compiling sqlite3 with a program


The thing is I'm not using a libary, I'm using the sources (.c and .h) of sqlite3.

But is it a better idea to to turn sqlite3 into a libary? could that work with c? btw I'm using the dev-c++ IDE.
  #4  
Old 16-Aug-2006, 02:16
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,281
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: linker errors while compiling sqlite3 with a program


So where are the functions defined in the source? Are they in both the CPP and H files? If not, you're missing a library. If so, be sure to include the proper header and build with the proper source file.
__________________

Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
  #5  
Old 16-Aug-2006, 03:51
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 991
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough

Re: linker errors while compiling sqlite3 with a program


I see you don't call sqlite3GetToken or sqlite3MPrintf in your file, so these functions must be called from within the other project (sqlite3). You only call the wrapper functions - that is what I suspect sqlite3_open and the others to be.

Therefore, either the sqlite3 project uses a library you didn't include, or - more likely - the 2 files you imported aren't the only files in that project. Check for additional includes the sqlite3 header and source file may have. If they aren't too long and you feel like it, you could post those 2 files here as well.

Best regards,
Lucian
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #6  
Old 17-Aug-2006, 01:38
davis
 
Posts: n/a

Re: linker errors while compiling sqlite3 with a program


Quote:
Originally Posted by ryver
The thing is I'm not using a libary, I'm using the sources (.c and .h) of sqlite3.

But is it a better idea to to turn sqlite3 into a libary? could that work with c? btw I'm using the dev-c++ IDE.

If you haven't built the sqlite library, build it first. You don't want to "use" any sqlite "c" files. You only want to include sqlite3.h. Take a look at the C example located at: www.sqlite.org

You will then link your program against the sqlite library.


:davis:
 
 

Recent GIDBlogI?m Home by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem compiling a program, my first vector. george89 C++ Forum 2 26-Jun-2006 22:10
In Need of Some Serious Help...compiling errors [C++] needcishelp C++ Forum 25 21-Dec-2005 02:26
Compiling/Linking roostercogburn C Programming Language 5 08-Nov-2005 15:32
Compiling Errors ToddSAFM C++ Forum 22 18-Dec-2004 12:42
compiling a program within another (C++) Siphiro C++ Forum 5 06-Feb-2004 16:35

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 07:01.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.