getopt and C++

Mark V. Meuer meuer at cs.umn.edu
Tue Mar 5 03:12:51 AEST 1991


In article <1991Mar04.161843.27932 at cs.ruu.nl>, markov at cs.ruu.nl (Mark Overmars) writes:
> I have a simple question: How do I use the routine getopt with C++. What I did
> was to put
> 
>    extern int getopt(int,char **,char *);
> 
> in the program. Now the loader complaints that getopt__FiPPcPc is undefined.
> 
> How do I solve this?
> 
> Mark Overmars

I *think* all you have to do is change the declaration to

	extern "C" {
		extern int getopt(int,char **,char *);
	} ;

and it should work correctly.   In general, when calling a C function, put
the declarations in a block preceeded by 'extern "C"' and life should be
wonderful.

-mark



More information about the Comp.sys.sgi mailing list