Why am I getting undefined references when using argtables?

Posted on 2006-03-20
Last Modified: 2007-12-19
I am fairly new to C++, and don't get to use it much on top of that, and I'm trying to learn how to use argtable. I have followed the tutorial that came with it but I keep getting the following undefined reference errors:

path/ undefined reference to `arg_filen'
path/ undefined reference to `arg_lit0'
path/ undefined reference to `arg_lit0'
path/ undefined reference to `arg_end'
path/ undefined reference to `arg_nullcheck'
path/ undefined reference to `arg_parse'
path/ undefined reference to `arg_print_errors'

My code is here:

#include <iostream>
#include <argtable2.h>
using namespace std;

#define EXIT_FAILURE 1

char *programName;

int main (int argc, char **argv)
  struct arg_file *directory;
  struct arg_lit *recursive, *help;
  struct arg_end *end;

  directory = arg_filen("d", "directory","<file>",0, 10, "Directory to index");
  recursive = arg_lit0("r", "recursive", "Crawl recursively");
  help = arg_lit0("h", "help", "Print this help and exit");
  end = arg_end(20);
  void *argtable[] = {directory, recursive, help, end};
  directory->filename[0] = ".";
  recursive->count = 1;
  // Check for NULL entries.
  if (arg_nullcheck(argtable) != 0)
    printf("error: insufficient memory\n");

  // Parse the command line arguments.
  int nerrors = arg_parse(argc,argv,argtable);

  // If errors, print them.
  if (nerrors > 0)
    arg_print_errors(stdout,end, "indexer");

  void arg_print_syntaxv(FILE *fp, void **argtable, const char *suffix);

What am I missing here? I have argtable2.h in my include directory. Any help appreciated.
$ locate argtable2.h


Question by:ibanja
    LVL 30

    Expert Comment

    Hi ibanja,
    > #include <argtable2.h>
    Try the following:
    #include "argtable2.h"

    David Maisonave (Axter)
    LVL 30

    Expert Comment

    Also, please post contents of argtable2.h

    Author Comment


    I tried #include "argtable2.h" but it still gives me the errors.  I even copied it into the same directory as my main program and still no go.

    Since it is fairly big I will give a link to argtable2.h.
    or here click on the 1.9

    LVL 86

    Expert Comment

    Your original post is not the full code, since the 1st error is reported on line 41, whereas you only have 36 lines, so I assume the problem comes from the missing part. Do you have a

    #define ARGTABLE2

    around? If so, remove it, since it would prevent the header file to be 'seen' and explain the errors.

    Author Comment


    Sorry I should have numbered the lines for clarity. The top of the original file is just the GNU license. Listed below are the lines the errors refer to:

    41  directory = arg_filen("d", "directory","<file>",0, 10, "Directory to index");
    42  recursive = arg_lit0("r", "recursive", "Crawl recursively");
    43  help = arg_lit0("h", "help", "Print this help and exit");
    44  end = arg_end(20);
    51  if (arg_nullcheck(argtable) != 0)
    55  int nerrors = arg_parse(argc,argv,argtable);
    59  arg_print_errors(stdout,end, "indexer");

    I don't have a #define ARGTABLE2 anywhere.

    I found the following in the libraries readme.txt file:
    Remember to update your system's LD_LIBRARY_PATH to include
    /usr/local/lib/ (the install location of the dynamic library)
    otherwise your applications won't be able to find it.

    The thing is the library is in /usr/lib
    /usr/lib/ ->

    But I don't see the variable LD_LIBRARY_PATH when I run the command "env" so I don't think this is the issue, however I am posting it in case I am missing something.  I've also tried putting symbolic links from the above lib files to /usr/local/lib.
    /usr/local/lib/libargtable2.a -> /usr/lib/libargtable2.a
    /usr/local/lib/ -> /usr/lib/
    /usr/local/lib/ -> /usr/lib/


    Author Comment

    Also, the header file should have all the necessary declarations.
    LVL 86

    Accepted Solution

    Hm, LD_LIBRARY_PATH is only of interest ar runtime. But, are you specifying the lib at all when compiling? Try adding '-largtable2' to your command line, e.g.

    g++ -largtable2

    Author Comment


    That did it.  Now I have to figure out how to set that in my  I am using automake.
    LVL 86

    Expert Comment

    How does that file look like?

    Author Comment

    The is listed below:


    #  uncomment the following if index requires the math library
    #index_LDADD=-lm index.texinfo help.txt doc

    #  if you write a self-test script named `chk', uncomment the
    #  following and add `chk' to the EXTRA_DIST list

    #  build and install the .info pages
    #info_TEXINFOS = index.texinfo
    #index_TEXINFOS = gpl.texinfo

    #  install the man pages

    Author Comment

    Thanks jkr,

    Adding the following line to the did it:


    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
    Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now