• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 625
  • Last Modified:

Why am I getting undefined references when using argtables?

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/index.cc:41: undefined reference to `arg_filen'
path/index.cc:42: undefined reference to `arg_lit0'
path/index.cc:43: undefined reference to `arg_lit0'
path/index.cc:44: undefined reference to `arg_end'
path/index.cc:51: undefined reference to `arg_nullcheck'
path/index.cc:55: undefined reference to `arg_parse'
path/index.cc:59: 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


  • 6
  • 3
  • 2
1 Solution
Hi ibanja,
> #include <argtable2.h>
Try the following:
#include "argtable2.h"

David Maisonave (Axter)
Also, please post contents of argtable2.h
ibanjaAuthor Commented:

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 http://cvs.sourceforge.net/viewcvs.py/argtable/argtable2/src/ click on the 1.9

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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.
ibanjaAuthor Commented:

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/libargtable2.so -> libargtable2.so.4

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/libargtable2.so -> /usr/lib/libargtable2.so.4
/usr/local/lib/libargtable2.so.4 -> /usr/lib/libargtable2.so.4

ibanjaAuthor Commented:
Also, the header file should have all the necessary declarations.
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++ index.cc -largtable2
ibanjaAuthor Commented:

That did it.  Now I have to figure out how to set that in my Makefile.am.  I am using automake.
How does that file look like?
ibanjaAuthor Commented:
The Makefile.am is listed below:


#  uncomment the following if index requires the math library

EXTRA_DIST=index.lsm.in index.texinfo index.spec.in 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
ibanjaAuthor Commented:
Thanks jkr,

Adding the following line to the Makefile.am did it:

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now