We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Why am I getting undefined references when using argtables?

ibanja
ibanja asked
on
Medium Priority
694 Views
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/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


Comment
Watch Question

AxterSenior Software Engineer

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

David Maisonave (Axter)
Cheers!
AxterSenior Software Engineer

Commented:
Also, please post contents of argtable2.h

Author

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
jkr
CERTIFIED EXPERT
Top Expert 2012

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

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

Author

Commented:
Also, the header file should have all the necessary declarations.
CERTIFIED EXPERT
Top Expert 2012
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
jkr,

That did it.  Now I have to figure out how to set that in my Makefile.am.  I am using automake.
jkr
CERTIFIED EXPERT
Top Expert 2012

Commented:
How does that file look like?

Author

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

Author

Commented:
Thanks jkr,

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


Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.