Monday, April 11, 2005

Compiling issue again

Tried to run
gcc -I/usr/include -lsocket send_smtp.c
and got

Undefined first referenced
symbol in file
gethostbyname /var/tmp/ccaFFX2O.o (symbol belongs to implicit dependency /usr/lib/libnsl.so.1)
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status

Went into /usr/lib and issued:

nm * | grep gethost | grep -v "UNDEF"

Here is the partial returns:

[399] | 303636| 12|FUNC |LOCL |0 |12 |Xegethostname
[2371] | 328548| 340|FUNC |LOCL |0 |12 |my_gethost
libc.a[gethostid.o]:
[5] | 0| 80|FUNC |GLOB |0 |2 |gethostid
[1] | 0| 0|FILE |LOCL |0 |ABS |gethostid.c
libc.a[gethostname.o]:
[5] | 0| 44|FUNC |GLOB |0 |2 |gethostname
[1] | 0| 0|FILE |LOCL |0 |ABS |gethostname.c
[3459] | 247796| 80|FUNC |GLOB |0 |9 |gethostid
[996] | 0| 0|FILE |LOCL |0 |ABS |gethostid.c
[4204] | 247876| 44|FUNC |GLOB |0 |9 |gethostname
[997] | 0| 0|FILE |LOCL |0 |ABS |gethostname.c
....
libnsl.a[gethostbyname_r.o]:
[11] | 200| 184|FUNC |GLOB |0 |2 |gethostbyaddr_r
[6] | 0| 200|FUNC |GLOB |0 |2 |gethostbyname_r
[1] | 0| 0|FILE |LOCL |0 |ABS |gethostbyname_r.c
libnsl.a[gethostent.o]:
[11] | 84| 132|FUNC |GLOB |0 |2 |gethostbyaddr
[8] | 0| 84|FUNC |GLOB |0 |2 |gethostbyname
[14] | 216| 84|FUNC |GLOB |0 |2 |gethostent

Now you see that gethostname is in the libc.a

gcc -I/usr/include -lsocket -lc send_smtp.c

but it did not work. Look through the above output, you can see that gethostname is in libnsl.a as well.

gcc -I/usr/include -lsocket -lnsl send_smtp.c

Then it worked.

Tip: nm command.
Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?