DaemonForums  

Go Back   DaemonForums > FreeBSD > FreeBSD General

FreeBSD General Other questions regarding FreeBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 8th May 2009
l2fl2f's Avatar
l2fl2f l2fl2f is offline
Real Name: Yves Guerin
Port Guard
 
Join Date: May 2008
Location: Montreal, Quebec, Canada
Posts: 25
Thanked 1 Time in 1 Post
Default compile c programme sqlite3

Hello,

I don't know how to compile this c programme on FreeBSD 6.4, need help

Code:
/*
  Very simple C program.

   Compile:
     gcc -o simplesqlite3 simplesqlite3.c  -Wall -W -O2 -Wl,-R/usr/local/lib -lsqlite3
  
   Note sqlite3 shared library, by default, installs in /usr/local/lib. 
   The compile command above will directly link the full path of 
   this library into this program.

*/



#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;
}
Thank you in advance.

Last edited by Carpetsmoker; 11th May 2009 at 03:23 AM. Reason: Add [code] tags
Reply With Quote
  #2   (View Single Post)  
Old 8th May 2009
DNAeon DNAeon is offline
Shell Scout
 
Join Date: Sep 2008
Location: Bulgaria
Posts: 138
Thanked 6 Times in 6 Posts
Default

Hi,

I've just looked over the code quickly, but what I see is missing are the arguments to the "callback" function..

Code:
rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg);
What are the errors that gcc is reporting?

P.S.: Please use the code tag - it makes it much more easier to review your code
__________________
"I never think of the future. It comes soon enough." - A.E

Useful links: FreeBSD Handbook | FreeBSD Developer's Handbook | The Porter's Handbook | PF User's Guide | unix-heaven.org
Reply With Quote
  #3   (View Single Post)  
Old 9th May 2009
TerryP's Avatar
TerryP TerryP is offline
Arp Constable
 
Join Date: May 2008
Location: USofA
Posts: 1,547
Thanked 112 Times in 104 Posts
Default

Whoever wrote the compilation instructions is an ass.

You must tell GCC where it can find A.) any needed libraries that are outside the standard paths, and B.) any needed include files that are outside the standard paths. Unless you wish to invoke the linker or the pre-processor directly, in which case you have to tell them instead of the gcc front end, respectively.

Add -I/usr/local/include -L/usr/local/lib to the compilation command.
__________________
My Journal

Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.
Reply With Quote
  #4   (View Single Post)  
Old 11th May 2009
l2fl2f's Avatar
l2fl2f l2fl2f is offline
Real Name: Yves Guerin
Port Guard
 
Join Date: May 2008
Location: Montreal, Quebec, Canada
Posts: 25
Thanked 1 Time in 1 Post
Thumbs up

Dear TerryP,

I grab the code on Internet and may be the code is for Linux Box. I try your hints and it works.

Thank you so much
Reply With Quote
  #5   (View Single Post)  
Old 11th May 2009
l2fl2f's Avatar
l2fl2f l2fl2f is offline
Real Name: Yves Guerin
Port Guard
 
Join Date: May 2008
Location: Montreal, Quebec, Canada
Posts: 25
Thanked 1 Time in 1 Post
Thumbs up

Dear DNAeon

I try the hints from TerryP and I works great

- csqlite3 test.db "CREATE TABLE adrip (adrip TEXT PRIMARY KEY);"
return nothing, so it seems ok
- csqlite3 test.db "INSERT INTO adrip VALUES ('127.0.0.1');"
return nothing, so it seems ok
- csqlite3 test.db "SELECT * FROM adrip;"
adrip = 127.0.0.1

so it works anyway

Thanks you for your help and your code review (the time you spend to understand the code)
Reply With Quote
Reply

Tags
compile sqlite

Thread Tools
Display Modes

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

BB 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
Can't compile gcc-4.3.3_20090101 troberts FreeBSD Ports and Packages 7 12th January 2009 10:30 PM
firefox3 will not compile map7 FreeBSD Ports and Packages 8 14th July 2008 11:23 PM
gio-fam-backend will not compile map7 FreeBSD Ports and Packages 0 2nd July 2008 01:59 AM
How come gnome2 won't compile? Damien787 FreeBSD Ports and Packages 10 16th June 2008 05:20 PM
Why wont this compile? Johnny2Bad FreeBSD General 10 19th May 2008 11:30 PM


All times are GMT. The time now is 11:34 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick