Thread: undefined reference to `sqlite3_initialize' ?

  1. #1
    Registered User
    Join Date
    Oct 2015
    Posts
    5

    Exclamation undefined reference to `sqlite3_initialize' ?

    I have been making a small application over linux in c with gtk and sqlite3 I am new to both gtk and sqlite3. I am having trouble in initializing sqlite3 library. I am unable to figure out whether my approach to initializing sqlite3 is wrong or there is something wrong with my makefile

    main.c

    Code:
    #include <stdio.h>
    #include <gtk/gtk.h>
    #include <stdlib.h>
    #include <string.h>
    #include <sqlite3.h>
    
    typedef struct loginer {
        GtkEntry *entry_uname; //username textbox
        GtkEntry *entry_upass; //pasword textbox
    }txtboxes;
    
    
    void init_db_messages() {
         GtkWidget* dialog;
    
         dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "the text");
         
         gtk_window_set_title(GTK_WINDOW(dialog), "the title");
    
         //gint result = 
    
         gtk_dialog_run(GTK_DIALOG(dialog));
    
              if(dialog!=NULL)
      {
        gtk_widget_hide(dialog);
        gtk_widget_destroy(dialog);
    //    gtk_widget_hide(window);
    //    gtk_widget_destroy(window);
      }
    
    }
    
    void init_db () {
            // initializing engine
            //int ret;
            do {
    
                if (SQLITE_OK != sqlite3_initialize()){
                    init_db_messages("Initialization Faliure", "uh , oh... failed to initialize library");
                    break;
                }
    
            }while(0);
    }
    
    G_MODULE_EXPORT void on_login_destroy ()
    {
        gtk_main_quit ();
    }
    
    
    G_MODULE_EXPORT void on_login_btn_clicked(GtkButton *button, txtboxes* gtexters, GtkWidget *window){
        char luemail[255];
        char lupass[255];
    
        //getting text from the text boxes
         const gchar *emailer = gtk_entry_get_text(gtexters->entry_uname);
         const gchar *passer = gtk_entry_get_text(gtexters->entry_upass);
    
         // getting text from text boxes (input)
         strcpy(luemail, emailer);
         strcpy(lupass, passer);
    
    
         //reversing and setting new text (output)
         gtk_entry_set_text(gtexters->entry_uname, lupass);
         gtk_entry_set_text(gtexters->entry_upass, luemail);
    
         init_db_messages();
    
    }
    
    
    int main(int argc, char **argv){
        GtkBuilder *builder;
        GtkWidget *window;
        txtboxes gtexters;
        GError *error = NULL;
        /* Init GTK+ */
        gtk_init( &argc, &argv );
    
        /* Create new GtkBuilder object */
        builder = gtk_builder_new();
        /* Load UI from file. If error occurs, report it and quit application.
         Replace "gui/login.glade" with your saved project with your startup form.*/
        if( ! gtk_builder_add_from_file( builder, "login.glade", &error )){
            g_warning( "%s", error->message );
            g_free( error );
            return( 1 );
        }
        /* Get main window pointer from UI */
        window = GTK_WIDGET( gtk_builder_get_object( builder, "login" ) );
        
        //connecting each structure member to it appropriate gtkwidget
        
        gtexters.entry_uname = GTK_ENTRY(gtk_builder_get_object(builder, "entry_uname" ));
        gtexters.entry_upass = GTK_ENTRY(gtk_builder_get_object(builder, "entry_upass" )); 
    
        /* Connect signals with appropriate handlers so that handlers could be called when button is clicked */
        gtk_builder_connect_signals( builder, &gtexters);
        /* Destroy builder, since we don't need it anymore */
        g_object_unref( G_OBJECT( builder ) );
        /* Show window. All other widgets are automatically shown by GtkBuilder */
        gtk_widget_show( window );
        /* Start main loop */
        gtk_main();
        return 0;
    }
    my make file

    Code:
    CC = gcc
    CFLAGS := $(shell pkg-config --cflags glib-2.0 gtk+-2.0 gmodule-2.0)
    LDFLAGS := $(shell pkg-config --libs glib-2.0 gtk+-2.0 gmodule-2.0)
    LIBS := -lsqlite3
    DEBUG = -Wall
    asitor: main.c
        $(CC) $(DEBUG) $(CFLAGS) $(LIBS) $< -o ../build/$@ $(LDFLAGS)
    in my linux system a simple c program with sqlite3 could be compiled as:

    Code:
    gcc sqlite.c -o sqlite_test -lsqlite3
    Any help is appreciated.

    The codes are under MIT license
    Last edited by Mr.Kumar; 10-12-2015 at 06:07 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,061
    What is the full command line that make prints when it executes that rule?

    For me, I'd put $(LIBS) at the end of the command line
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2015
    Posts
    5

    The Full Error

    The full error:

    Code:
    gcc -Wall -pthread -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/include/gtk-2.0 -I/usr/lib/i386-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/libpng12 -I/usr/include/harfbuzz   -lsqlite3 main.c -o ../build/asitor -Wl,--export-dynamic -pthread -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfontconfig -lgobject-2.0 -lfreetype -lgmodule-2.0 -lglib-2.0   
    /tmp/ccwZDj55.o: In function `init_db':
    main.c:(.text+0x9a): undefined reference to `sqlite3_initialize'
    collect2: ld returned 1 exit status
    make: *** [asitor] Error 1
    Also git repository:

    https://github.com/Mr-Kumar-Abhishek/Asitor

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,061
    Folded for readability
    Code:
    $ xsel | sed 's/ /\n/g'
    gcc
    -Wall
    -pthread
    -I/usr/include/glib-2.0
    -I/usr/lib/i386-linux-gnu/glib-2.0/include
    -I/usr/include/gtk-2.0
    -I/usr/lib/i386-linux-gnu/gtk-2.0/include
    -I/usr/include/atk-1.0
    -I/usr/include/cairo
    -I/usr/include/gdk-pixbuf-2.0
    -I/usr/include/pango-1.0
    -I/usr/include/gio-unix-2.0/
    -I/usr/include/freetype2
    -I/usr/include/pixman-1
    -I/usr/include/libpng12
    -I/usr/include/harfbuzz
    -lsqlite3
    main.c
    -o
    ../build/asitor
    -Wl,--export-dynamic
    -pthread
    -lgtk-x11-2.0
    -lgdk-x11-2.0
    -latk-1.0
    -lgio-2.0
    -lpangoft2-1.0
    -lpangocairo-1.0
    -lgdk_pixbuf-2.0
    -lcairo
    -lpango-1.0
    -lfontconfig
    -lgobject-2.0
    -lfreetype
    -lgmodule-2.0
    -lglib-2.0
    Like I said, $(LIBS) is too early on the command line.

    > main.c.text+0x9a): undefined reference to `sqlite3_initialize'
    Searching sqlite3 for symbols BEFORE you have any symbols to resolve doesn't make sense.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Salem View Post
    Searching sqlite3 for symbols BEFORE you have any symbols to resolve doesn't make sense.
    This is one thing that I've always found a little frustrating about GCC. I never quite understood why they make operations so sensitive to the order of command line arguments.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  6. #6
    Registered User
    Join Date
    Oct 2015
    Posts
    5
    Got it thank you

  7. #7
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Quote Originally Posted by Elkvis View Post
    This is one thing that I've always found a little frustrating about GCC. I never quite understood why they make operations so sensitive to the order of command line arguments.
    May be they should sorta rearrange command line arguments so that '-lblahblah' comes after everything else.

    I doubt upstream gives a ........ about such issues though :-D

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. undefined reference
    By slyer4ever in forum C Programming
    Replies: 11
    Last Post: 01-07-2014, 04:17 PM
  2. Several, undefined reference to...
    By Or1gin in forum C++ Programming
    Replies: 7
    Last Post: 08-09-2013, 06:02 PM
  3. undefined reference to...
    By catasturslykid in forum C Programming
    Replies: 2
    Last Post: 07-28-2013, 09:02 AM
  4. Undefined reference to...
    By legendus in forum C Programming
    Replies: 19
    Last Post: 10-25-2009, 06:18 AM
  5. Undefined Reference to...
    By JJFMJR in forum C++ Programming
    Replies: 3
    Last Post: 08-16-2008, 03:09 AM

Tags for this Thread