socket errors [Archive] - C Board

PDA

View Full Version : socket errors


xlordt
09-21-2003, 06:00 PM
I am tring to run a socket programm on windows 9x and im using bloodshed but i keep getting an error everytime i try to run a program using socket( AF_INET, SOCK_STREAM, 0 )

ERR: C:\WINDOWS\TEMP\ccB8edgb.o(.text+0x3c):1.c: undefined reference to `socket@12'

Does anyone know why i keep getting this err?

XSquared
09-21-2003, 06:06 PM
Are you linking to the appropriate libraries?

xlordt
09-21-2003, 06:09 PM
errr linking.. i didnt know i hade to link any files... what files do i have to link.. in bloodshed to make this work, I know in linux.. there is no linking in volve

Thantos
09-21-2003, 06:15 PM
You can only do it in a project. Goto Project Options, then Parameters, click on "Add library and object", add "libwsock32.a"

xlordt
09-21-2003, 06:33 PM
hmm damn ok i did what ya told me to do .. and now i get

g++: C:\Dev-C++\Lib\libwsock32: No such file or directory
g++: file path prefix `C:\DEV-C_~1\BIN\' never used

xlordt
09-21-2003, 06:46 PM
nm i got it

xlordt
09-21-2003, 06:59 PM
blah.. check it .. i ran a sample code in my project and i keep getting the perror ( what am i doing wrong here )


#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <sys/types.h>
#include <winsock.h>
#include <errno.h>

int main(int argc, char *argv[])
{
struct sockaddr_in socketz; /* Structure of socket */
int s_sock; /* Socket status */


if(( s_sock = socket( AF_INET, SOCK_STREAM, 0 )) == -1 )
{
perror( "Error" );
exit( 1 );
}

printf( "Socket status: ON!\n" );
return 0;
}

chrismiceli
09-21-2003, 07:10 PM
to program in windows sockets, you need to run WSAStartup and WSACleanup, not exactly sure how they work, I use linux, but those functions tell which version of winsock to use so you don't get those undefined errors, probably fixing the perror thing also. try searching here for more on WSAStartup and all
http://msdn.microsoft.com
or go to google and search beej, and feel lucky.

Thantos
09-21-2003, 08:30 PM
1) You don't need that many header files to run the code you gave
2) Expand your code to find out what the error is.
3) chrismiceli is right about WSAStartup() being need

xlordt
09-21-2003, 10:15 PM
Ya thanx.. btw... the header files are added.. cause i will be adding more to that code.. =) thanx again

Thantos
09-21-2003, 11:14 PM
the header files are added.. cause i will be adding more to that code

But if you are getting errors it helps to eliminate all unneeded stuffs. Then go back in and add as you need, that way if you start getting errors again it is easier to figure out what is causing it.

xlordt
09-23-2003, 02:09 PM
ya that is true.. thanx again all