From: barbour AT hpfcalb DOT fc DOT hp DOT com (Tony Barbour) Subject: Linking MS .LIBs and cygwin.dll 2 Dec 1997 19:49:19 -0800 Message-ID: <199712022021.NAA28882.cygnus.gnu-win32@hpfcalb.fc.hp.com> Mime-Version: 1.0 Content-Type: text/plain; charset=X-roman8 Content-Transfer-Encoding: 7bit To: gnu-win32 AT cygnus DOT com 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 #include #include #include 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 AT cygnus DOT com" with one line of text: "help".