'function name' is an undefined reference error

I am using WATCOM 16 bit compiler and WATT32 socket library for simple socket program that should run in 16 bit DOS system.

I am getting the below showed error please help me…

C:\DOCUME~1\Mahendra\Desktop\watt\ZIPFIL~1>wcl /l=dos client.c
Open Watcom C/C++16 Compile and Link Utility Version 1.8
Portions Copyright (c) 1988-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See openwatcom.org/ for details.
wcc CLIENT.C
DOS/4GW Protected Mode Run-time Version 1.97
Copyright (c) Rational Systems, Inc. 1990-1994
Open Watcom C16 Optimizing Compiler Version 1.8
Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See openwatcom.org/ for details.
CLIENT.C(46): Warning! W131: No prototype found for function ‘htons’
CLIENT.C(66): Warning! W131: No prototype found for function ‘close’
CLIENT.C: 69 lines, included 6431, 2 warnings, 0 errors
Code size: 208
wlink @wcl.lnk
DOS/4GW Protected Mode Run-time Version 1.97
Copyright (c) Rational Systems, Inc. 1990-1994
Open Watcom Linker Version 1.8
Portions Copyright (c) 1985-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See openwatcom.org/ for details.
loading object files
searching libraries
Error! E2028: gethostbyname_ is an undefined reference
Error! E2028: socket_ is an undefined reference
Error! E2028: htons_ is an undefined reference
Error! E2028: connect_ is an undefined reference
Error! E2028: recv_ is an undefined reference
creating a DOS executable
file CLIENT.obj(C:\DOCUME~1\MAHENDRA\DESKTOP\WATT\ZIPFIL~1\CLIENT.C): undefined
symbol gethostbyname_
file CLIENT.obj(C:\DOCUME~1\MAHENDRA\DESKTOP\WATT\ZIPFIL~1\CLIENT.C): undefined
symbol socket_
file CLIENT.obj(C:\DOCUME~1\MAHENDRA\DESKTOP\WATT\ZIPFIL~1\CLIENT.C): undefined
symbol htons_
file CLIENT.obj(C:\DOCUME~1\MAHENDRA\DESKTOP\WATT\ZIPFIL~1\CLIENT.C): undefined
symbol connect_
file CLIENT.obj(C:\DOCUME~1\MAHENDRA\DESKTOP\WATT\ZIPFIL~1\CLIENT.C): undefined
symbol recv_
Error: Linker returned a bad status


This simple socket code which one i m trying to compile…

/*

  • client.c – a stream socket client demo
    */
    #include <stdio.h>
    #include <stdlib.h>
    #include <errno.h>
    #include <string.h>
    #include <netdb.h>
    #include <sys/types.h>
    #include <netinet/in.h>
    #include <sys/socket.h>

#define PORT 3490 /* the port client will be connecting to */

#define MAXDATASIZE 100 /* max number of bytes we can get at once */

int main (int argc, char **argv)
{
struct hostent he;
struct sockaddr_in their_addr; /
connector’s address information */
int sockfd, numbytes;
char buf[MAXDATASIZE];

if (argc != 2)
{
fprintf (stderr,“usage: client hostname\n”);
return (1);
}

if ((he = gethostbyname(argv[1])) == NULL) /* get the host info */
{
perror (“gethostbyname”);
return (1);
}

if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
perror (“socket”);
return (1);
}

their_addr.sin_family = AF_INET; /* host byte order /
their_addr.sin_port = htons(PORT); /
short, network byte order */
their_addr.sin_addr = *((struct in_addr )he->h_addr);
memset (&their_addr.sin_zero,0,8); /
zero the rest of the struct */

if (connect(sockfd, (struct sockaddr*)&their_addr,
sizeof(struct sockaddr)) == -1)
{
perror (“connect”);
return (1);
}

if ((numbytes = recv(sockfd, buf, MAXDATASIZE, 0)) == -1)
{
perror (“recv”);
return (1);
}

buf[numbytes] = ‘\0’;

printf (“Received: %s”,buf);
close (sockfd);
return (0);
}

Some obvious questions.

  1. Why are you asking this question in a QNX forum?
  2. Why are you using Watcom to compile? (The company was sold but the compiler was ditched a number of years ago)
  3. Why are you running DOS?
  4. How many DOS systems do you know of that supported TCP/IP sockets? The first Microsoft system that had network support was Windows 3.1.

Hi maschoen,

      Watcom compiler i m using to get 16 bit .exe which should run in Watcom and one more thing is it has WATT32 socket library.

Our client is having DOS 16 bit system and they want the application should run on that system only.
This DOS system has TCP/IP sockets that is sure. Tha WATT32 socket library is made for DOS systems only.

Well you skipped my first question, probably the most important one. I don’t think anyone here knows anything about getting Watcom to do sockets on a DOS system.

Even without that, it is a pretty bizarre request of your client to get sockets working on a DOS system. You might just as well have been asked to get it running on an Apple 2.