Problem of compiling and linking the C/C++ program using WIN32API with GCC

Alain Nguyen
Mon May 28 14:24:00 GMT 2007


I am a new CYGWIN user.

I actually tried to compile and link a C/C++ program using the 'w32api',
more exactly, the '/lib/w32api/libws2_32.a' library, with the following

            $gcc   -o myprogram   -lws2_32    -c myprogram.c

But, I always got the error messages from the 'ld' linker dynamic, such as:

    -         "Undefined reference to 'WSAcleanup@0'"
    -         "Undefined reference to 'WSAstartup@8'"
    -         "Undefined reference to '_inet_addr@4'"
    -         "Undefined reference to '_socket@12'"
    -         "Undefined reference to '_connect@12'"
    -         etc...

    "collect2: ld returned 1 exit status"

This means that the linker dynamic 'ld' is unable to find and open the
corresponding 'libws2_32.a' library file.

I've also tried several other solutions, such as:

            $ gcc  -o myprogram   -L  /usr/lib   -lws2_32   -c myprogram.c


            $ gcc  -o myprogram    -l /usr/lib/w32api/libws2_32.a   -c

With these solutions, I've got the error message from 'ld' like this:

    "Cannot find the -l/usr/lib/w32api/libws2_32.a"
    "collect2: ld returned 1 exit status"

Someone can help me to resolve this problem


Unsubscribe info:
Problem reports:

More information about the Cygwin mailing list