Libary Trouble

This is a discussion on Libary Trouble within the C Programming forums, part of the General Programming Boards category; I'm building a library based on Allegro for my commonly used code. The compile works, but when the linker kicks ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    11

    Unhappy Libary Trouble

    I'm building a library based on Allegro for my commonly used code. The compile works, but when the linker kicks in I'm given an error message that one of the functions it contains cannot be found. Have I overlooked something here?

    Here's an overview of the code:

    Library
    jlib/jlib.h
    Code:
    void increment_global_timer();
    void init_global_timer();
    jlib/jlib.c
    Code:
    #include <allegro.h>
    #include "jtimer.h" // only contains 'int init();'
    
    volatile int global_timer;
    
    void increment_global_timer()
    // [ place another frame onto the stack ] //
    {
      ++global_timer;
    }
    END_OF_FUNCTION (increment_global_timer);
    
    // [ setup the global timer ] //
    void init_global_timer()
    {
      LOCK_VARIABLE(global_timer);
      LOCK_FUNCTION(increment_global_timer);
    
      install_int_ex(increment_global_timer, BPS_TO_TIMER(60));
    
      // [ randomise ] //
      srand ((unsigned int)time(NULL));
    }
    jlib.h
    Code:
    #include "jlib/jtimer.h"
    Game
    Code:
    #include <allegro.h>
    #include <jlib.h>
    #include "init.h"
    #include "maps.h"
    
    int init()
    {
      allegro_init();
      install_timer();
      install_keyboard();
    
      init_global_timer();
    
      init_maps();
    }
    Error
    [Linker error] undefined reference to `init_global_timer'
    Cheers.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    You need to tell the linker the name and location of your 'jlib' library.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    11

    Smile

    Thanks. Specifying its location worked.

    How would I go about getting it to link via a simple -jlib or -ljlib flag at the command line instead of its entire path?

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    Assuming gcc, the -L flag allows you to specify library search directories.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble with assignment in C
    By mohanlon in forum C Programming
    Replies: 17
    Last Post: 06-23-2009, 10:44 AM
  2. Replies: 6
    Last Post: 01-03-2007, 02:02 PM
  3. Is it so trouble?
    By Yumin in forum Tech Board
    Replies: 4
    Last Post: 01-30-2006, 03:10 PM
  4. trouble scanning in... and link listing
    By panfilero in forum C Programming
    Replies: 14
    Last Post: 11-21-2005, 11:58 AM
  5. C++ program trouble
    By senrab in forum C++ Programming
    Replies: 7
    Last Post: 04-29-2003, 11:55 PM

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