Hello everybody,
When I compiled a socket program under QNX6.20 ,the follow error messages
occured:
cc tut6.c -o tut6.out
/tmp/AAA921634_cc.o: In function main': /tmp/AAA921634_cc.o(.text+0x13): undefined reference to
socket’
/tmp/AAA921634_cc.o(.text+0x63): undefined reference to bind' /tmp/AAA921634_cc.o(.text+0xa7): undefined reference to
getsockname’
/tmp/AAA921634_cc.o(.text+0x104): undefined reference to listen' /tmp/AAA921634_cc.o(.text+0x118): undefined reference to
accept’
cc: /usr/bin/ntox86-ld error 1
and I found the ntox86-ld is a symbolic link to ld.
My program like this:
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#define TRUE 1
/*
- This program creates a socket and then begins an infinite
loop. Each time
- through the loop it accepts a connection and prints out
messages from it.
- When the connection breaks, or a termination message comes
through, the
- program accepts a new connection.
*/
main()
{
int sock, length;
struct sockaddr_in server;
int msgsock;
char buf[1024];
int rval;
/* Create socket /
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
perror(“opening stream socket”);
exit(1);
}
/ Name socket using wildcards */
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
server.sin_port = 0;
if (bind(sock, (struct sockaddr )&server,
sizeof(server))) {
perror(“binding stream socket”);
exit(1);
}
/ Find out assigned port number and print it out */
length = sizeof(server);
if (getsockname(sock, (struct sockaddr *)&server,
&length)) {
perror(“getting socket name”);
exit(1);
}
printf(“Socket has port #%d\n”, ntohs(server.sin_port));
/* Start accepting connections /
listen(sock, 5);
do {
msgsock = accept(sock, 0, 0);
if (msgsock == -1) {
perror(“accept”);
return EXIT_FAILURE;
} else do {
memset(buf, 0, sizeof(buf));
if ((rval = read(msgsock, buf, 1024)) <
0)
perror(“reading stream message”);
else if (rval == 0)
printf(“Ending connection\n”);
else
printf("–>%s\n", buf);
} while (rval > 0);
close(msgsock);
} while (TRUE);
/
- Since this program has an infinite loop, the socket
“sock” is
- never explicitly closed. However, all sockets will be
closed
- automatically when a process is killed or terminates
normally.
*/
}
What is wrong with these codes?
Thanks for any suggestion.
–
Hichun Chen
try linking with the socket library. cc … -l socket …
“Hichun Chen” <hcchen@mail.ipp.ac.cn> wrote in message
news:auk6q8$8kj$1@inn.qnx.com…
Hello everybody,
When I compiled a socket program under QNX6.20 ,the follow error messages
occured:
cc tut6.c -o tut6.out
/tmp/AAA921634_cc.o: In function main': /tmp/AAA921634_cc.o(.text+0x13): undefined reference to
socket’
/tmp/AAA921634_cc.o(.text+0x63): undefined reference to bind' /tmp/AAA921634_cc.o(.text+0xa7): undefined reference to
getsockname’
/tmp/AAA921634_cc.o(.text+0x104): undefined reference to listen' /tmp/AAA921634_cc.o(.text+0x118): undefined reference to
accept’
cc: /usr/bin/ntox86-ld error 1
and I found the ntox86-ld is a symbolic link to ld.
My program like this:
#include <sys/types.h
#include <sys/socket.h
#include <netinet/in.h
#include <netdb.h
#include <stdio.h
#include <string.h
#include <unistd.h
#include <stdlib.h
#define TRUE 1
/*
- This program creates a socket and then begins an
infinite
loop. Each time
- through the loop it accepts a connection and prints
out
messages from it.
- When the connection breaks, or a termination message
comes
through, the
- program accepts a new connection.
*/
main()
{
int sock, length;
struct sockaddr_in server;
int msgsock;
char buf[1024];
int rval;
/* Create socket /
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
perror(“opening stream socket”);
exit(1);
}
/ Name socket using wildcards */
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
server.sin_port = 0;
if (bind(sock, (struct sockaddr )&server,
sizeof(server))) {
perror(“binding stream socket”);
exit(1);
}
/ Find out assigned port number and print it out */
length = sizeof(server);
if (getsockname(sock, (struct sockaddr *)&server,
&length)) {
perror(“getting socket name”);
exit(1);
}
printf(“Socket has port #%d\n”, ntohs(server.sin_port));
/* Start accepting connections */
listen(sock, 5);
do {
msgsock = accept(sock, 0, 0);
if (msgsock == -1) {
perror(“accept”);
return EXIT_FAILURE;
} else do {
memset(buf, 0, sizeof(buf));
if ((rval = read(msgsock, buf, 1024))
-
perror(“reading stream
message”);
else if (rval == 0)
printf(“Ending connection\n”);
else
printf("–>%s\n", buf);
} while (rval > 0);
close(msgsock);
} while (TRUE);
/*
- Since this program has an infinite loop, the
socket
“sock” is
- never explicitly closed. However, all sockets will
be
closed
- automatically when a process is killed or
terminates
normally.
*/
}
What is wrong with these codes?
Thanks for any suggestion.
–
Hichun Chen
“Paul Vander Byl” <paul@gandacar.ca> wrote in message
news:aukprt$rj2$1@inn.qnx.com…
try linking with the socket library. cc … -l socket …
Thank you very much,Paul.
However,under QNX4.25 these codes needn’t link with any socket libraries,why
does it so complex at QNX6.20 system?( only for me just for modularity?
and the online documents don’t write very clear(I think the documents
contained in QNX4.25 are more detail).
Under QNX4 you used Watcom and not gcc. And Watcom had some magic for
telling the toolchain what libs where required in the headers. Linking
with the proper libraries is the norm on UNIX and Neutrino is much more
like a UNIX then QNX4.
chris
Hichun Chen <hcchen@mail.ipp.ac.cn> wrote:
“Paul Vander Byl” <> paul@gandacar.ca> > wrote in message
news:aukprt$rj2$> 1@inn.qnx.com> …
try linking with the socket library. cc … -l socket …
Thank you very much,Paul.
However,under QNX4.25 these codes needn’t link with any socket libraries,why
does it so complex at QNX6.20 system?( only for me > > just for modularity?
and the online documents don’t write very clear(I think the documents
contained in QNX4.25 are more detail).
–
Chris McKillop <cdm@qnx.com> “The faster I go, the behinder I get.”
Software Engineer, QSSL – Lewis Carroll –
http://qnx.wox.org/