This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: libiberty.a and getopt problem
- From: David Fritz <zeroxdf at att dot net>
- To: cygwin at cygwin dot com
- Date: Mon, 02 Feb 2004 16:01:30 -0500
- Subject: Re: libiberty.a and getopt problem
- References: <002501c3e982$09877b40$0100a8c0@TAMAHOME>
The opt* variables are declared __declspec(dllimport) in Cygwin's
headers. So when you're program refers to optarg after having included
Cygwin's <getopt.h> (or <unistd.h>), the symbol your program links to is
called __imp__optarg. Presumably, the opt* variables were not declared
dllimport when libiberty was compiled. So when you link to libiberty,
your program and libiberty's getopt() are referring to two different
optarg variables.
You can work around this problem by not including <getopt.h> or
<unistd.h>. Though, obviously, this is not a long-term solution.
#include <stdio.h>
extern char *optarg;
int main(int argc, char **argv)
{
int opt;
while ((opt = getopt(argc, argv, "avzdrkp:s:o:R:")) != -1) {
printf("opt = %d,%c\n", opt, opt);
printf("optarg = %s\n", optarg);
}
}
-----
~$ gcc test.c
Info: resolving _optarg by linking to __imp__optarg (auto-import)
~$ ./a -s 1
opt = 115,s
optarg = 1
~$ gcc test.c -liberty
~$ ./a -s 1
opt = 115,s
optarg = 1
~$
Cheers
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/