This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Linking MS .LIBs and cygwin.dll




I'm having trouble porting an application from UNIX to NT 4.0, and I've
been trying to use the cygwin32.dll to emulate the UNIX layers.  My problem
is that I also need to use some of the .LIB libraries provided by Microsoft 
(MSVC++ 4.0), and they don't seem to want to play nice together.  
I've gone through this list's archives and tried several things, but haven't 
been able to get everything to work together.  I've seen several places that
say that if you want help, you need to be specific, so this may be a little
long.

It says in the documentation, that to be able to use both kinds of modules,
I will have to use link.exe instead of ld.  I've found this to be true.  So to 
start, I wrote a small dummy program with some calls to cygwin functions 
that I need and try to link it with link.exe.  So I write a program (end of 
this message), and link it with link.exe (and crt0.o, libcygwin.a, 
libkernel32.a libgcc.a ) and I get some undefined externals, namely 
__data_start__, __data_end__, __bss_start__, __bss_end__.  Looking through 
the mailing list archives, I find that as long as I'm not using fork(), I don't 
need these, so I dummy them out, link fine with link.exe, but when I run, 
I never get to my main().  I look at the mailing list archives and see that a 
small #ifndef to some gas code (obj-coff.c) might help, but does not seem 
to work for me.  So I figure that since my main isn't getting called, 
I'd try /ENTRY:mainCRTStartup.  Still no call to my main.  

Ok, maybe Microsoft's startup code is easier to deal with, so after checking 
the mailing list archives, I find that I can create a .LIB from a .DLL using 
dumpbin and lib, so I apply that process to cygwin.dll and create a cygwin.lib.
I link my program with cygwin.lib, kernel32.lib, user32.lib, and libcd.lib, and 
I find that my main() does get called.  getenv() works, gettimeofday() works,
but when I try fileno() on stdin and/or stdout, I get the same result, 0.  
When I take that result and pass it to tcgetattr() (with a pointer to a 
termios struct), I get an access violation :

    The Instruction at 0x10023893 referenced memory at 0x00000054.  
    The memory could not be "read".

So it looks to me like stdout and/or stdin is being set up differently by the 
MS startup code than cygwin expects.

So if I use cygwin startup code, I can't find my main(), and if I use MS startup
code, stdin and stdout are unavailable.

Has anyone succesfully used .LIBs and cygwin calls in an application?  Which 
startup code did you use?  How did you link?  Anyone?

Thanks,
Tony

-----
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <termios.h>

char _data_start__, _data_end__, _bss_start__, _bss_end__;

int main()
{
 int fd;
 register char *termcap_name;
 struct termios ttybuff;
 struct timeval et0;
 int tty;

 printf("Starting\n");

 tty = fileno(stdin);

 printf("fileno for stdin = %d\n",tty);

 tty = fileno(stdin);
 printf("fileno for stdout = %d\n",tty);

 gettimeofday(&et0,NULL);

 printf("%d sec %d usec\n",et0.tv_sec, et0.tv_usec);
 termcap_name = getenv("TERMCAP");
 
 tcgetattr(tty,&ttybuff);

 printf("c_iflag = 0x%x, c_oflag= 0x%x c_cflag = 0x%x\n",ttybuff.c_iflag,ttybuff.c_oflag,ttybuff.c_cflag);

  
}




-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]