urgent help: link error

urgent help: link error

Post by Top Gu » Tue, 22 Apr 1997 04:00:00



This is a multi-part message in MIME format.
--------------1BA5EDA78E2E4199684A61AC
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi,

    i've tried to compile a c program called "server.c" and my compiler
told me that:
    ** the c source files are attached in this message **

    Don't know why? i am using Solaris 2.5 x86 and a SUN c compiler is
installed properly. i've tried to compile them in my college (Alpha
workstations) and ok. Can you help me?

Script started on Mon Apr 21 01:23:28 1997
/home2/se5a01/cn  % cc server.c -o server
Undefined   first referenced
 symbol         in file
socket                              server.o
accept                              server.o
bind                                server.o
listen                              server.o
ld: fatal: Symbol referencing errors. No output written to server
/home2/se5a01/cn  % ^D  
script done on Mon Apr 21 01:23:49 1997

------------------------------------------------------
Nelson Chan (chnel...@asiaonline.net)
UIN : 486565
--------------1BA5EDA78E2E4199684A61AC
Content-Type: text/plain; charset=us-ascii; name="client.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="client.c"

/*
 * Definition for TCP and UDP client/server programs
 */

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

char *pname;
#include <string.h>
#define MAX_MESSAGE 80

int send_message(int, char *, int);
int recv_message(int, char *, int);

main (int argc, char *argv[])
{
int sockfd, clilen, port;
struct sockaddr_in cli_addr, serv_addr;

int i, rc, wc;
char message[MAX_MESSAGE];

        if (argc != 4)
        {
                printf("Usage: %s <ip-addr> <port> <message>\n", argv[0]);
                exit(-1);
        }

        pname = argv[0];
        port = atoi(argv[2]);

        /* Open a TCP socket (an Internet stream socket). */

        if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) < 0)
        {
                perror("client: can't open stream socket");
                exit(-1);
        }

        /* Bind our local address so that the client can send to us */

        memset((char *) &serv_addr, sizeof(serv_addr), (char) 0);
        serv_addr.sin_family = PF_INET;
        serv_addr.sin_addr.s_addr = inet_addr(argv[1]);
        serv_addr.sin_port = htons(port);

        if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
        {
                perror("client: can't connect to server");
                exit(-1);
        }

        printf("client: message sent %s\n", argv[3]);
        send_message(sockfd, argv[3], strlen(argv[3])+1);
        rc = recv_message(sockfd, message, MAX_MESSAGE);
        printf("client: message received %s\n", message);

}

int recv_message(int fd, char *buf, int maxlen)
{
int rc, i;
        for (i=0; i < maxlen;)
        {
                if ((rc = read(fd, &buf[i], 1)) == 1)
                {
                        i++;
                        if (buf[i-1] == 0)
                                break;
                }
                else if (rc == 0)
                        return(i);
                else
                {
                        perror("server: can't read data");
                        return(i);
                }
        }
        return(i);

}

int send_message(int fd, char *buf, int maxlen)
{
int nleft, wc;

        nleft = maxlen;
        for (; nleft;)
        {
                wc = write(fd, buf, nleft);
                if (wc < 0)
                {
                        perror("server: can't write");
                        return(maxlen - nleft);
                }
                nleft -= wc;
                buf += wc;
        }

}

--------------1BA5EDA78E2E4199684A61AC
Content-Type: text/plain; charset=us-ascii; name="server.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="server.c"

/*
 * Definition for TCP and UDP client/server programs
 */

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

char *pname;
#include <string.h>
#define MAX_MESSAGE 80

int send_message(int, char *, int);
int recv_message(int, char *, int);

main (int argc, char *argv[])
{
int sockfd, newsockfd, clilen, childpid, port;
struct sockaddr_in cli_addr, serv_addr;

int i, rc, wc;
char message[MAX_MESSAGE];

        if (argc != 2)
        {
                printf("Usage: %s <port>\n", argv[0]);
                exit(-1);
        }

        pname = argv[0];
        port = atoi(argv[1]);

        /* Open a TCP socket (an Internet stream socket). */

        if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
        {
                perror("server: can't open stream socket");
                exit(-1);
        }

        /* Bind our local address so that the client can send to us */

        memset((char *) &serv_addr, sizeof(serv_addr), (char) 0);
        serv_addr.sin_family = AF_INET;
        serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
        serv_addr.sin_port = htons(port);

        if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
        {
                perror("server: can't bind local address");
                exit(-1);
        }

        listen(sockfd, 5);

        for (;;)
        {
                /* wait for a connection from a client process. */

                clilen = sizeof(cli_addr);
                newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr,
                        &clilen);

                if (newsockfd < 0)
                {
                        perror("server: accept error");
                        exit(-1);
                }

                /* read a string from the client */
                rc = recv_message(newsockfd, message, MAX_MESSAGE);
                if (rc == 0)
                {
                        close(newsockfd);
                        continue; /* connection terminted */
                }
                else if (send_message(newsockfd, message, rc) != rc)
                {
                        printf("server: write error\n");
                        close(newsockfd);
                        continue;
                }

        }

}

int recv_message(int fd, char *buf, int maxlen)
{
int rc, i;
        for (i=0; i < maxlen;)
        {
                if ((rc = read(fd, &buf[i], 1)) == 1)
                {
                        i++;
                        if (buf[i-1] == 0)
                                break;
                }
                else if (rc == 0)
                        return(i);
                else
                {
                        perror("server: can't read data");
                        return(i);
                }
        }
        return(i);

}

int send_message(int fd, char *buf, int maxlen)
{
int nleft, wc;

        nleft = maxlen;
        for (; nleft;)
        {
                wc = write(fd, buf, nleft);
                if (wc < 0)
                {
                        perror("server: can't write");
                        return(maxlen - nleft);
                }
                nleft -= wc;
                buf += wc;
        }

}

--------------1BA5EDA78E2E4199684A61AC--
 
 
 

urgent help: link error

Post by Tony #35 » Tue, 22 Apr 1997 04:00:00



said:

Top> first referenced symbol in file socket server.o accept
Top> server.o bind server.o listen server.o ld: fatal:
Top> Symbol referencing errors. No output written to server

Have you tried reading the (section 3n) man page for
"socket", "accept" etc?

Look at the SYNOPSIS section.

hth,
tony

 
 
 

urgent help: link error

Post by R!ch » Tue, 22 Apr 1997 04:00:00



> Hi,

>     i've tried to compile a c program called "server.c" and my compiler
> told me that:
>     ** the c source files are attached in this message **

>     Don't know why? i am using Solaris 2.5 x86 and a SUN c compiler is
> installed properly. i've tried to compile them in my college (Alpha
> workstations) and ok. Can you help me?

> Script started on Mon Apr 21 01:23:28 1997
> /home2/se5a01/cn  % cc server.c -o server
> Undefined   first referenced
>  symbol         in file
> socket                              server.o
> accept                              server.o
> bind                                server.o
> listen                              server.o
> ld: fatal: Symbol referencing errors. No output written to server

You need to link with -lsocket and -lnsl.

Have a look in the FAQ.

--
R!ch

If it ain't analogue, it ain't music.
#include <disclaimer.h>                          \\|// - ?
                                                 (o o)
          /==================================oOOo=(_)=oOOo========\

          |  Sun Service Contractor                               |
          |                            Voice: +44 (0)1276 691974  |
          |                                 .oooO                 |
          |                                  (  )  Oooo.          |
          \===================================\ (==(   )==========/
                                               \_)  ) /
                                                   (_/

 
 
 

urgent help: link error

Post by Cameron Lai » Tue, 22 Apr 1997 04:00:00




                        .
                        .
                        .

Quote:>    i've tried to compile a c program called "server.c" and my compiler
>told me that:

                        .
                        .
                        .
Quote:>/home2/se5a01/cn  % cc server.c -o server
>Undefined   first referenced
> symbol         in file
>socket                              server.o
>accept                              server.o
>bind                                server.o
>listen                              server.o
>ld: fatal: Symbol referencing errors. No output written to server

                        .
                        .
                        .
Instead of "cc server.c -o server", command
"cc server.c -o server -lsocket -lnsl".
--

Cameron Laird           http://starbase.neosoft.com/~claird/home.html

                        +1 713 996 8546 FAX

 
 
 

1. ftp/urgent/urgent/urgent

iam using linux
i am having problem witha user not being able to ftp in to the server
with in the lan. all other users can. I checked the follwing files
 484 Feb 28 10:30 /etc/ftpaccess
 456 Feb 28 10:30 /etc/ftpconversion
  39 Feb 28 10:30 /etc/ftpgroups
 104 Feb 28 10:30 /etc/ftphosts
  79 Feb 28 10:30 /etc/ftpusers
they don't have much in them.

the error message logged is Aug  4 15:13:10 linus ftpd[7144]: failed
login from linus [192.168.254.26]

any clues

please help

Sent via Deja.com http://www.deja.com/
Before you buy.

2. printer compatibility

3. URGENT URGENT URGENT

4. ext2/3 updates for 2.5.44 (1/11): Default mount options in superblock

5. ftp problem/urgent/urgent/urgent

6. Please Help Me> Factorials Programming!

7. URGENT URGENT dlopen() help needed...

8. EXA Byte TAPE Driver under Linux ?

9. URGENT - Help tracking down PHP upgrade error 4.1.2 -> 4.2.3

10. URGENT help request: hard disk errors

11. URGENT NEED HELP - FSCK ERRORS

12. HELP+URGENT: cannot access my home dir after a crash (job-working-directory error