[BUG 1.7 getopt_long() and recv()] has problem for tftp-hpa-5.0 on cygwin-1.7/win2003

Charles Wilson cygwin@cwilson.fastmail.fm
Sun Jun 14 10:01:00 GMT 2009


Xiaoqiang Zheng wrote:
> to make the 2 BUGs more clear:
> 
> * in the while loop of processing options with '-' using
> getopt_long():
> 
> $ tftpd/tftpd -u SYSTEM -L -vvvv -p -c -s /var/log
> 
> 1. it seems the '-<x> <value>'(-u SYSTEM) argument pairs that pass
> the second argument as value have the value lost and the variable get
> null value. the '-<x>'(-L -p -c -s; -vvvv is a special one) type
> arguments that set some flag seems work well.

Here's your problem:
gcc  tftp.o main.o ../common/libcommon.a -liberty
/home/Administrator/tftp-hpa-5.0/lib/libxtra.a  -o tftp.exe

you're linking against libiberty.  You're using the getopt functions
from libiberty, which are locally bound to the optind variable inside
the -liberty library.  However, main.c probably #included getopt.h,
which on cygwin has declspec(dllimport) declarations for optind -- so,
main.o is actually linking to "__imp__optind", a redirection pointer to
the optind variable inside cygwin1.dll.

Therefore, when your main.o code tries to access optind, it "sees" the
one in cygwin1.dll, which is never incremented past one.  When you call
getopt/getopt_long, you're calling the implementation in libiberty
(which manipulates the liberty's version of the optind variable).

The solution to this problem is to either

1) don't link to libiberty, or at least, insure that -lcygwin precedes
-liberty on the link line, OR
2) do NOT include getopt.h or unistd.h, and instead force to declare all
the relevant functions and variables consistent with the versions in
-liberty (that is, without declspec(dllimport) decorations).

Try the attached getopt_decls.h file from checkx-0.2.0.  unchanged, it
implements option #1 (with a little help from the Makefile).  However,
change the #ifdef and it implements #2.

--
Chuck
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: getopt_decls.h
URL: <http://cygwin.com/pipermail/cygwin/attachments/20090614/dab56ba2/attachment.h>
-------------- next part --------------
--
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/


More information about the Cygwin mailing list