Undefined Reference with Windows Socket

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Undefined Reference with Windows Socket

ALEXANDRE BORGES GONCALVES
Hi there,

I am trying a problem when I compile the follow  program

#include<windows.h>
#include<winsock.h>

int do_something(){
       
        SOCKET socket_handle=socket(PF_INET, SOCK_DGRAM, 0);
        if(socket_handle==INVALID_SOCKET){
                return(0);
        }
       
        closesocket(socket_handle);
        return(1);
}

I have got these messages

C:\MinGWStudio\Programs\ksocket\ksocket.c:8: undefined reference to `socket@12'
C:\MinGWStudio\Programs\ksocketl\Debug\ksocket.o(.text+0x3e):C:\MinGWStudio\Programs\ksocket\ksocket.c:13:
undefined reference to `closesocket@4'

I think that I must link the program to winsock.dll. Is that rigth?
How can I do this?

Thanks in advance

------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

_______________________________________________
This list observes the Etiquette found at http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.
Reply | Threaded
Open this post in threaded view
|

Re: Undefined Reference with Windows Socket

Jonathan Schleifer-4
"ALEXANDRE BORGES GONCALVES" <[hidden email]> wrote:

> I have got these messages
>
> C:\MinGWStudio\Programs\ksocket\ksocket.c:8: undefined reference to
> `socket@12'
> C:\MinGWStudio\Programs\ksocketl\Debug\ksocket.o(.text+0x3e):C:\MinGWStudio\Programs\ksocket\ksocket.c:13:
> undefined reference to `closesocket@4'

Try -lws2_32 or -lwsock32.

--
Jonathan

------------------------------------------------------------------------------

_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

_______________________________________________
This list observes the Etiquette found at http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

signature.asc (817 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Undefined Reference with Windows Socket

ALEXANDRE BORGES GONCALVES
Thank you, Jonathan.
It works perfectly.
[]

2008/12/25, Jonathan Schleifer <[hidden email]>:

> "ALEXANDRE BORGES GONCALVES" <[hidden email]> wrote:
>
>> I have got these messages
>>
>> C:\MinGWStudio\Programs\ksocket\ksocket.c:8: undefined reference to
>> `socket@12'
>> C:\MinGWStudio\Programs\ksocketl\Debug\ksocket.o(.text+0x3e):C:\MinGWStudio\Programs\ksocket\ksocket.c:13:
>> undefined reference to `closesocket@4'
>
> Try -lws2_32 or -lwsock32.
>
> --
> Jonathan
>

------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

_______________________________________________
This list observes the Etiquette found at http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.