NuSphere Forums Forum Index
NuSphere Forums
Reply to topic


Joined: 10 May 2004
Posts: 3
Reply with quote
ddmitrie wrote:
Since there is getopt() available with unistd.h, it's easier to remove #include getopt.h from all the dbg-cli sources Smile


Unfortunately, neither the system getopt.h nor unistd.h implement getopt_long_only. I've tried various bypasses and includes, but always get this:

Code:
g++ -DHAVE_CONFIG_H -I. -I. -I..   -I/sw/include -I../dbgbase  -g -O2 -c -o dbg_cli-main.o `test -f 'main.cpp' || echo './'`main.cpp
main.cpp: In function `int main(int, char**)':
main.cpp:94: error: `getopt_long_only' undeclared (first use this function)
main.cpp:94: error: (Each undeclared identifier is reported only once for each
   function it appears in.)
make: *** [dbg_cli-main.o] Error 1


Any further ideas? Is getopt_long_only() really needed?
thanks! Smile
View user's profileFind all posts by ecantuSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8342
Reply with quote
take a look into /usr/include/unistd.h
maybe it's possible to bypass declaration of getopt() in it.
For example, there might be some #ifdef around getopt() ...
In this case it would be sufficient to define them and have getopt() declared only once in getopt.h
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 10 May 2004
Posts: 3
Reply with quote
Ok...this is really kludgy, but it works. I really don't see the need for unistd.h to need to define getopt because any autoconf will find getopt.h on its own, so this workaround will do for this build. I'll keep it around until I see something breaking with future compiles.

Here is a diff for my new unistd.h:

Code:
*** /usr/include/unistd.h-dist  Sat Sep 13 22:41:28 2003
--- /usr/include/unistd.h       Fri May 14 11:31:48 2004
***************
*** 180,186 ****
 
  extern char *optarg;                  /* getopt(3) external variables */
  extern int optind, opterr, optopt, optreset;
! int    getopt(int, char * const [], const char *);
 
  #ifndef       _POSIX_SOURCE
  #ifdef        __STDC__
--- 180,186 ----
 
  extern char *optarg;                  /* getopt(3) external variables */
  extern int optind, opterr, optopt, optreset;
! /* int         getopt(int, char * const [], const char *); */
 
  #ifndef       _POSIX_SOURCE
  #ifdef        __STDC__


Here are the commands that I used to compile the program:
Code:
$ CPPFLAGS='-I/sw/include' LDFLAGS='-L/sw/lib -R/sw/lib' ./configure --prefix=/usr/local
$ make  (ignore warnings about "multiple definitions of symbol xxx")
$ make install


That's it! This build assumes pcre, readline, and ncurses are installed (in my case, via fink).

Hopefully this helps some people. Now I have to figure out how to use this properly. Wink Thanks for all the help, Dmitiri!
View user's profileFind all posts by ecantuSend private message


Joined: 07 Aug 2004
Posts: 2
Location: France
Reply with quote
ecantu wrote:
Ok...this is really kludgy, but it works. I really don't see the need for unistd.h to need to define getopt because any autoconf will find getopt.h on its own, so this workaround will do for this build. I'll keep it around until I see something breaking with future compiles.


Kludgy? Hell, that's vomit-inducing. I can't even believe you'd consider doing it. There is no excuse, I repeat, NO excuse for a piece of user software requiring you to modify system headers. What you're risking there is getting dbg-cli to build and having other stuff mysteriously fail to compile.

The problem here is in the dbg-cli code, and in particular it's autoconfigure setup.

As you have noted, the code uses getopt_long_only, which appears to be used in the place of getopt_long despite having the option of short options. Funky. OSX has no getopt_long_only, but does have getopt_long. So, we can replace the call to getopt_long_only with a call to getopt_long, remove all reference to the included ../getopt and all should be well. A quick hack to dbg/main.cpp and dbg/Makefile (to remove the -lgetopt and -I../getopt) works quite nicely, I find. I'd fix the root problem, but I have more important stuff to do.

Oh, and then you can restore your unistd.h to its former glory.

Simon

_________________
Your mouse has moved. You must restart Windows NT for this change to be recognised.
View user's profileFind all posts by tuftySend private message


Joined: 31 Oct 2004
Posts: 3
Reply with quote
See this: viewtopic.php?t=5855
View user's profileFind all posts by djissSend private message
DBG-CLI on OS X
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 2 of 2  

  
  
 Reply to topic