libargp: argp_program_version does not work
Andrew Schulman
schulman.andrew@epa.gov
Thu Jul 11 22:02:00 GMT 2013
> > Hello!
> >
> > I have found a problem: argp_program_version string is ignored by libargp.
>
> Hi Pavel. Thanks for reporting this. I confirm your observation. For
> example, when I compile argp's example #2
> (http://www.gnu.org/software/libc/manual/html_node/Argp-Example-2.html#Argp-Example-2),
> the --version option doesn't work.
>
> > I guess the problem happens because of DLL's nature. DLLs cannot contain
> > unresolved symbols, so the DLL has own version of argp_program_version which
> > is always initialized to NULL. There's no way to override it.
>
> Also confirmed. argp.h declares argp_program_version as
>
> extern const char *argp_program_version;
>
> But gllib/argp-pv.c initializes it as
>
> const char *argp_program_version = (const char *) 0
>
> Whether there's a way to override that value by one declared in the user's
> code, I don't know. Maybe a linker switch?
OK, I remembered how this works. To override the initial values in your
program, you just have to reassign them at run time.
Here's how it's done with argp's example #2. Note the first two lines of
main(), which aren't present in the upstream example.
/*** Begin modified argp example #2 ***/
#include <argp.h>
const char version[] = "argp-ex2 1.0";
const char bug_address[] = "<bug-gnu-utils@gnu.org>";
/* Program documentation. */
static char doc[] = "Argp example #2 -- a pretty minimal program using
argp";
static struct argp argp = { 0, 0, 0, doc };
int main (int argc, char **argv)
{
argp_program_version = version;
argp_program_bug_address = bug_address;
argp_parse (&argp, argc, argv, 0, 0, 0);
}
/*** End modified argp example #2 ***/
If you compile the above version, you'll see that the --version option and
bug tracker text are available.
I'm sure this problem is familiar to developers and users of shared
libraries, but I had forgotten it. I'll add a note to the Cygwin README
file, to help all of us remember it next time.
Andrew
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
More information about the Cygwin
mailing list