LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-16-2010, 02:22 PM   #1
Inhumed
LQ Newbie
 
Registered: Aug 2010
Posts: 5

Rep: Reputation: 0
getopt.h compilation error on linux


Hello linuxquestions,

I am using the function "getopt_long_only" in getopt.h to parse the command line options of my C++ program. The program compiles and runs fine on windows 7 with mingw and g++. But when I compile it with g++ on my Debian system (latest stable release) I get these errors:

Code:
/usr/include/getopt.h: In function ‘int getopt(int, char* const*, const char*)’:
/usr/include/getopt.h:153: error: expected primary-expression before ‘,’ token
/usr/include/getopt.h: In function ‘int getopt_long(int, char* const*, const char*, const option*, int*)’:
/usr/include/getopt.h:162: error: expected primary-expression before ‘,’ token
/usr/include/getopt.h: In function ‘int getopt_long_only(int, char* const*, const char*, const option*, int*)’:
/usr/include/getopt.h:166: error: expected primary-expression before ‘,’ token
I couldn't find anyone with a similar problem by searching on google and since I am not that great at C/C++ programming at the moment, I am not sure whats wrong (if anything) with getopt.h.

Any help or direction to documentation and information is appreciated!

Thanks,
Inhumed

Edit: Not sure If I need to add the getopt.h code to this post, I have not edited it ever and I have the newest version of glib that the debian main server offers, But here is the problematic part of getopt.h:

It seems to not like the THROW lines
Code:
#ifdef __GNU_LIBRARY__

/* Many other libraries have conflicting prototypes for getopt, with
   differences in the consts, in stdlib.h.  To avoid compilation
   errors, only prototype getopt for the GNU C library.  */

extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
      __THROW;

#else /* not __GNU_LIBRARY__ */

extern int getopt ();

#endif /* __GNU_LIBRARY__ */

#ifndef __need_getopt

extern int getopt_long (int ___argc, char *const *___argv,
			const char *__shortopts,
		        const struct option *__longopts, int *__longind)
       __THROW;
extern int getopt_long_only (int ___argc, char *const *___argv,
			     const char *__shortopts,
		             const struct option *__longopts, int *__longind)
       __THROW;

#endif

Last edited by Inhumed; 08-16-2010 at 03:58 PM.
 
Old 08-16-2010, 08:23 PM   #2
Meson
Member
 
Registered: Oct 2007
Distribution: Arch x86_64
Posts: 606

Rep: Reputation: 67
You probably have an extra semicolon or unbalanced bracket somewhere. You really need to post your code though if you want help.
 
Old 08-17-2010, 07:31 PM   #3
Inhumed
LQ Newbie
 
Registered: Aug 2010
Posts: 5

Original Poster
Rep: Reputation: 0
I am not sure I do, I copied over the _mingw.h and the getopt.h from the mingw include folder and compiled it with my code on linux and received no errors and the program runs fine.
 
Old 08-17-2010, 07:34 PM   #4
Meson
Member
 
Registered: Oct 2007
Distribution: Arch x86_64
Posts: 606

Rep: Reputation: 67
Again, post your code for real help. Did you include your own header above getopt.h which might have had an error in it, but didn't materialized until getopt.h?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Don't know how to solve the Perl dependency (Getopt::Std) error that yum update gives info2share Linux - Software 2 07-07-2009 03:18 AM
error during compilation of linux kernel zahidul Linux - Newbie 2 10-18-2008 11:25 AM
alsaconf returns error msg "getopt: command not found" bezdomny Linux - Hardware 4 07-13-2007 09:20 AM
error: getopt is missing but required. hybridstorm Linux - Software 0 06-17-2005 11:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration