Computing.Net > Forums > Programming > C++ HELP - symbol reference errors

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

C++ HELP - symbol reference errors

Reply to Message Icon

Name: brb183
Date: October 1, 2008 at 14:29:38 Pacific
OS: unix
CPU/Ram: c
Product: c
Comment:

gcc -ggdb -c pcs.c
gcc -ggdb -o pcs pcs.o -lm
Undefined first referenced
symbol in file
recv pcs.o
send pcs.o
gethostbyname pcs.o
socket pcs.o
connect pcs.o
ld: fatal: Symbol referencing errors. No output written to pcs
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `pcs'

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>

#define PORT 0x1234
#define HOST "myHost"
#define DIRSIZE 8192

int main(int argc, char *argv[])
{
char hostname[100];
char dir[DIRSIZE];
int sd;
struct sockaddr_in sin;
struct sockaddr_in pin;
struct hostent *hp;

strcpy(hostname,HOST);
if (argc>2)
{ strcpy(hostname,argv[2]); }

/* go find out about the desired host machine */
hp = gethostbyname(hostname);

/*if ((hp = gethostbyname(hostname)) == 0) {
perror("gethostbyname");
exit(1);
}*/

/* fill in the socket structure with host information */
memset(&pin, 0, sizeof(pin));
pin.sin_family = AF_INET;
pin.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr;
pin.sin_port = htons(PORT);

/* grab an Internet domain socket */
if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
perror("socket");
exit(1);
}

/* connect to PORT on HOST */
connect(sd,(struct sockaddr *) &pin, sizeof(pin));
/* if (connect(sd,(struct sockaddr *) &pin, sizeof(pin)) == -1) {
perror("connect");
exit(1);
}*/

/* send a message to the server PORT on machine HOST */
send(sd, argv[1], strlen(argv[1]), 0);
/*if (send(sd, argv[1], strlen(argv[1]), 0) == -1) {
perror("send");
exit(1);
}*/

/* wait for a message to come back from the server */
recv(sd, dir, DIRSIZE, 0);
/*if (recv(sd, dir, DIRSIZE, 0) == -1) {
perror("recv");
exit(1);
}*/


printf("%s\n", dir);

close(sd);

return 0;
}




Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: October 1, 2008 at 18:28:03 Pacific
Reply:

That error means it can't find the recv() and the send() functions. Depending on your platform, it may be as simple as including a link to libsocket.


0

Response Number 2
Name: brb183
Date: October 1, 2008 at 18:33:49 Pacific
Reply:

bingo. THANK YOU!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: C++ HELP - symbol reference errors

c++ program help www.computing.net/answers/programming/c-program-help/5336.html

C++ undefined symbol error message www.computing.net/answers/programming/c-undefined-symbol-error-message/15076.html

C help plz www.computing.net/answers/programming/c-help-plz/424.html