Please Help!! Calling Socket function in a dll file (that is created using cygwin library), by a Microsoft Visual C++ program resulting in infinite loop

Brian Dessent
Wed May 9 23:59:00 GMT 2007

kalasad mailu wrote:

> I used the socket.h file provided by cygwin(/usr/include/cygwin/.) and
> wrote a program to create socket, made this a dll file and used this
> dll in VC++.
> I assume using of the socket.h( form cygwin) did all the conversion
> form the linux system calls to the windows system calls and made my
> socket program work. Please correct me if my understanding is wrong.

A header file does not implement anything.  It contains no code at all
(except in the case of C++ or inlined functions.)  It only describes an
interface that is actually implemented in a library.  In the case of
Cygwin, the standard C library is implemented by cygwin1.dll, along with
many POSIX functions.

> Now I want to try the same process for simple c++ functions like
> "cout". I don't find any cygwin header files like iostream.h or
> stream.h in the cygwin directory.

cout is part of the C++ standard library (STL) and is implemented by
libstdc++ which is part of gcc.

> When I created this stand alone program.
> #include <iostream>
> int main () {
>     std::cout << "Hello World\n";
>     return 0;
> }
> I guess this picked the header file from
> "cygwin\lib\gcc\i686-pc-cygwin\3.4.4\include\c++\" (a gcc header file)
> Is there no iostream header file by cygwin (/usr/include/cygwin)?

First of all, stop looking in /usr/include/cygwin for things, and stop
worrying about which directory header files are in.  That has no bearing
on what library implements a specific function, as all headers for all
installed libraries are in /usr/include.  Some of these headers are
provided by Cygwin.  The ones in the "cygwin" subdirectory are only for
Cygwin-specific things, but this is only a small fraction of the
functionality provided by Cygwin.  For example, all of the stadard C
library functions (such as stdio.h, stdlib.h, io.h, stdint.h, and on and
on) are all implemented by Cygwin, i.e. cygwin1.dll, and are in
/usr/include.  And many other libraries as well, such as zlib, gettext,
libintl, and so on.  So, stop confusing a header file with the library
that implements the code and realize that the location a header file
resides on disk has no relationship at all to the implementation.

> I am running into header file conflict when I also include both cygwin
> header files and the gcc header files. How to solve the conflict?

No, there's no conflict.  Gcc implements some libraries of its own, and
Cygwin provides most of the standard C library.  

> Is it possible to make a dll that uses the functions defined by the
> gcc header file(***not the cygwin header file i.e. present in
> (/usr/include/cygwin)***) and use it in the MSVC++?

Stop thinking of things by directory!  Look at the headers in the cygwin
package (cygcheck -l cygwin).  This represents everything implemented by
cygwin1.dll.  See that there are many things outside of

Now look at the libraries provided by gcc for the C++ runtime (cygcheck
-l gcc-g++).  See that gcc implements most of the C++ runtime
functionality.  There are all designed to perfectly coexist, there is no
problem with using both in a given program or DLL.

As to using something in MSVC, first of all libstdc++ is gcc specific,
so there is no way to use it at the source level with anything else. 
YOu can link to it at the binary level, i.e. call code written by g++
from MSVC, but only if the interface is 'extern "C"', because the two
compilers have different C++ ABIs which cannot coexist.

> If including the header file from gcc works then why is cygwin
> providing separate header files(like stdio.h, stdlib.h and etc in
> /usr/include/cygwin)?

Different headers provide different things.  /usr/include/stdio.h
provides the standard C library interface.  /usr/include/sys/stdio.h
provides low level implementation details.  You do not normally write
#include <sys/stdio.h>, as it is included by other headers
automatically.  Stop focusing on the location of things, and think of it
as an interface.  When you use #include <stdio.h> you are using a
certain interface; the details of how it is implemented are not your
concern.  stdio.h could include /usr/include/foo/bar/baz.h if it wanted


Unsubscribe info:
Problem reports:

More information about the Cygwin mailing list