delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/04/29/04:21:11

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <4090BB69.6000300@yahoo.fr>
Date: Thu, 29 Apr 2004 10:23:05 +0200
From: bertrand marquis <bertrand_marquis AT yahoo DOT fr>
Reply-To: bertrand_marquis AT yahoo DOT fr
User-Agent: Mozilla/5.0 (X11; U; Linux i686; fr-FR; rv:1.2.1) Gecko/20030225
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: libiberty and getopt
References: <4090B4EF DOT 4060204 AT yahoo DOT fr>
In-Reply-To: <4090B4EF.4060204@yahoo.fr>
X-Spam-Checker-Version: SpamAssassin 2.61 (1.212.2.1-2003-12-09-exp) on donald.sysgo.com
X-Spam-Level:
X-Spam-Status: No, hits=-4.9 required=5.0 tests=BAYES_00 autolearn=no version=2.61
X-AntiVirus: checked by AntiVir MailGate (version: 2.0.1.16; AVE: 6.25.0.2; VDF: 6.25.0.38; host: balu)
X-IsSubscribed: yes
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id i3T8L9av002668

Hi again,

    i just find the solution to my problem
    in fact it seems that adding:

extern int optind;
extern char *optarg;

solve the problem. The compiler then auto-import these variables and it 
is working after. This problem doesn't seem to exist under linux but it 
could be a difference in versions between my linux and my cygwin.

bertrand marquis a écrit:

> Hi,
>
>    I need to compile a program using libiberty.a and the function 
> getopt_long. When compiling with the flag -liberty my program crash 
> because it don't take the right arguments from the command line. But 
> without libiberty this part work before.
>
> i made a small program showing that problem, if anyone has an idea ?
> i'm using the latest cygwin from the installer ,gcc-3.3.1 and ld 
> 2.15.90 20040312
>
> thanks
>
> You can find next my source code for the test program and the result i 
> have with it.
>
>
> My test program:
>
> /*begin of argu.c*/
> #include <unistd.h>
> #include <getopt.h>
> #include <ctype.h>
> #include <stdio.h>
>
> int main(int argc, char **argv) {
>
>    struct option long_opts[] = {
>    {"v", 1, 0, 'v'},
>    {"no-v", 0, 0, 'V'},
>    {"k", 1, 0, 'k'},
>    {"no-k", 0, 0, 'K'},
>    {"l", 1, 0, 'l'},
>    {"no-l", 0, 0, 'L'},
>    {0, 0, 0, 0}
>    };
>    int c;
>    while ((c = getopt_long(argc, argv, "v:Vk:Kl:L:",
>        long_opts, NULL)) != EOF) {
>
>    switch(c) {
>    case 'v':
>        printf("v %s\n",optarg);
>        break;
>    case 'V':
>        printf("V\n");
>        break;
>    case 'k':
>        printf("k %s\n",optarg);
>        break;
>    case 'K':
>        printf("K\n");
>        break;
>    case 'l':
>        printf("l %s\n",optarg);
>        break;
>    case 'L':
>        printf("L\n");
>        break;
>    case '?':
>        printf("other:%c\n",c);
>    }
>    }
>    printf("argc=%d , optind=%d , 
> file=%s\n",argc,optind,argc>optind?*(argv+optind):"none");
>    return 0;
> }
> /*end of argu.c*/
>
> when you compile it with : gcc argu.c -o argu.exe it works:
> $ ./argu.exe -v abc -K test
> v abc
> K
> argc=5 , optind=4 , file=test
>
> but when you compile it with gcc argu.c -o argu.exe -liberty it gives:
> $ ./argu.exe -v abc -K test
> v (null)
> K
> argc=5 , optind=1 , file=-v
>
>
>
>
> -- 
> 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/
>



--
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/


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019