Hi, do you know what I do wrong?
This code is under udpclient.c :
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#define DATA “The sea is calm tonight, the tide is full . . .”
main(int argc, char *argv[])
{
int sock;
struct sockaddr_in name;
struct hostent *hp, *gethostbyname();
/* Create socket on which to send. /
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0) {
perror(“opening datagram socket”);
exit(1);
}
/
- Construct name, with no wildcards, of the socket to
- send to. Gethostbyname() returns a structure including
- the network address of the specified host. The port
- number is taken from the command line.
/
hp = gethostbyname(argv[1]);
if (hp == 0) {
fprintf(stderr, “%s: unknown host\n”, argv[1]);
exit(2);
}
memcpy(&name.sin_addr, hp->h_addr, hp->h_length);
name.sin_family = AF_INET;
name.sin_port = htons(atoi(argv[2]));
/ Send message. */
if (sendto(sock, DATA, sizeof(DATA), 0,
(struct sockaddr *)&name, sizeof(name)) < 0)
perror(“sending datagram message”);
close(sock);
}
It an example from the developper 's guide…
in the terminal, I type :
$
qcc -Isocket -Iin -Itypes -Inetdb -Istdio -Istring -Istdlib -Iunistd -g -Vgc
c_ntox86 -o test /home/udpclient.c
And it tells me : undefine reference to “socket”, and the same for
"gethostbyname"and “sendto”…
I guess it’s a problem of path.
Do I have to put -I/usr/define/sys/socket (didn’t work)
-I/usr/define/sys/socket.h (didn’t work)
-I usr/define/sys/socket (didn’t work)
Or maybe in the udpclient.c file …
I know it’s a stupid one…
Thanks for any help,
STARN
arno stoum <starn@yucom.be> wrote:
Hi, do you know what I do wrong?
This code is under udpclient.c :
Snip code
It an example from the developper 's guide…
in the terminal, I type :
$
qcc -Isocket -Iin -Itypes -Inetdb -Istdio -Istring -Istdlib -Iunistd -g -Vgc
c_ntox86 -o test /home/udpclient.c
And it tells me : undefine reference to “socket”, and the same for
"gethostbyname"and “sendto”…
Try
qcc -lsocket -o test /home/udpclient.c
^
L not I
-Peter
Peter,
I tried $ qcc -Lsocket -o test /home/udpclient.c
before it was:
/home/udpclient.c:25: undefined reference to “socket”
same for “gethostbyname” and “sendto”
now :
/tmp/AAA663587_CC.o(.text+0x10): undefined reference to “socket”
same for “gethostbyname” and “sendto”
It didn’t change that much… I guess it’s just because I didn’t
type -Vgcc_ntox86…
I read somewhere that " tcp/ip had to be running somewhere " or something
like that… But I can’t find the page anymore… You know something about
that?
Thanks a lot anyway! You got something else I could try?
STARN (sorry for my English…)
$ qcc -o test /home/udpclient.c -lsocket
arno stoum <starn@yucom.be> wrote:
: Peter,
: I tried $ qcc -Lsocket -o test /home/udpclient.c
Peter meant that the correct option is -l (i.e. a lowercase L), not an
uppercase I. If you need more information, see the documentation.
Steve Reid stever@qnx.com
TechPubs (Technical Publications)
QNX Software Systems
I don’t know why but it seems to work now.
But I have an other problem :
“.h No such file or directorynet” if I compile with qcc
" implicit declaration of “inet_addr” " if I change .c by .cpp and qcc by
QCC
thanks for the help!!
STARN
That was a funny problem:
“.h No such file or directorynet”
" implicit declaration of " int inet_addr(…)" " (inet_addr declaration
is under arpa/inet.h)
I couldn’t see anything wrong with my udp.c file under QNX so I tried
compile it with Visual C++. I just opened the file and I saw that the “.h>”
of " #include<arpa/inet.h> " was a line under " #define<arpa/inet "…
like that:
#define <arpa/inet
…h>
And I couldn’t see anything with QNX !!!
I really don’t know what hapenned… Maybe a cut and paste problem…
STARN