C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 02-15-2010, 07:15 PM   #1
Registered User
 
Join Date: Feb 2010
Posts: 3
Question MinGW and SQLite

Hi I am a seasoned C# developer trying to learn Objective-C using MinGW.

I have a working install of Objective-C and am trying to work with SQLite.
I have the SQLite3.dll in C:\windows\system32 (on the path), sqlite3.h in the include directoy (C:\MinGW\include) and libsqlite3.a in the lib directory (c:\MinGW\lib).

When I try to compile

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

static int callback(void *NotUsed, int argc, char **argv, char **azColName){
int i;
NotUsed=0;

for(i=0; i<argc; i++){
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}

int main(int argc, char **argv){
sqlite3 *db;
char *zErrMsg = 0;
int rc;

if( argc!=3 ){
fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]);
exit(1);
}
rc = sqlite3_open(argv[1], &db);
if( rc ){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg);
if( rc!=SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
}
sqlite3_close(db);
return 0;
}

simply with gcc sqltest.c -o sqltest, I get the error "undefined reference to 'sqlite3_open'"

It is picking up the header as it recognises the sqlite type.

Do I need to specify linking in the library or should it just pick it up from the default lib directory?

Any help is greatly appreciated as I seem to be missing something fundamental.

Thanks in advance.

Carl
CarlGB is offline   Reply With Quote
Old 02-15-2010, 07:31 PM   #2
Registered User
 
Join Date: Feb 2010
Posts: 3
See an absolute newbie.

I needed to specify -lsqlite3 simple as.
CarlGB is offline   Reply With Quote
Old 02-15-2010, 07:33 PM   #3
Registered User
 
Join Date: Oct 2006
Location: Canada
Posts: 1,243
You likely have to specify that you're linking to the library. Look around in the documentation for the API, it may be something like "-lsqlite3" that you have to pass to gcc.

EDIT: I see you got it.

Last edited by nadroj; 02-15-2010 at 07:36 PM.
nadroj is offline   Reply With Quote
Old 02-15-2010, 07:50 PM   #4
Registered User
 
Join Date: Feb 2010
Posts: 3
Smile

Quote:
Originally Posted by nadroj View Post
You likely have to specify that you're linking to the library. Look around in the documentation for the API, it may be something like "-lsqlite3" that you have to pass to gcc.

EDIT: I see you got it.
I found it in the end but appreciate you taking the time to respond, thanks.
CarlGB is offline   Reply With Quote
Old 02-15-2010, 07:54 PM   #5
Registered User
 
Join Date: Oct 2006
Location: Canada
Posts: 1,243
You're quite welcome.
nadroj is offline   Reply With Quote
Old 02-15-2010, 10:30 PM   #6
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 12,459
Quote:
Originally Posted by CarlGB
I have the SQLite3.dll in C:\windows\system32 (on the path), sqlite3.h in the include directoy (C:\MinGW\include) and libsqlite3.a in the lib directory (c:\MinGW\lib).
Have you considered just compiling with the SQLite amalgamation?
__________________
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is offline   Reply With Quote
Reply

Tags
mingw sqlite sqlite3 db

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQLite not performing update OnionKnight C Programming 0 01-21-2009 04:21 PM


All times are GMT -6. The time now is 12:05 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22