Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Delivered-To: mailing list cygwin@cygwin.com Message-ID: <401EBAAA.505@att.net> Date: Mon, 02 Feb 2004 16:01:30 -0500 From: David Fritz User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4 MIME-Version: 1.0 To: cygwin@cygwin.com Subject: Re: libiberty.a and getopt problem References: <002501c3e982$09877b40$0100a8c0@TAMAHOME> In-Reply-To: <002501c3e982$09877b40$0100a8c0@TAMAHOME> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes The opt* variables are declared __declspec(dllimport) in Cygwin's headers. So when you're program refers to optarg after having included Cygwin's (or ), 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 or . Though, obviously, this is not a long-term solution. #include 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/