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
/usr/include/argtable2.h

Thanks,
ibanja


ibanjaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

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

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.

http://cvs.sourceforge.net/viewcvs.py/argtable/argtable2/src/argtable2.h?rev=1.9&view=auto
or here http://cvs.sourceforge.net/viewcvs.py/argtable/argtable2/src/ click on the 1.9

Thanks,
ibanja
0
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

jkrCommented:
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.
0
ibanjaAuthor Commented:
jkr,

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

0
ibanjaAuthor Commented:
Also, the header file should have all the necessary declarations.
0
jkrCommented:
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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ibanjaAuthor Commented:
jkr,

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

bin_PROGRAMS=index
index_SOURCES=index.cc

#  uncomment the following if index requires the math library
#index_LDADD=-lm

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
#TESTS=chk

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

#  install the man pages
#man_MANS=index.1
0
ibanjaAuthor Commented:
Thanks jkr,

Adding the following line to the Makefile.am did it:
index_LDADD=-largtable2  


0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.