PDA

View Full Version : how to add library files to current library


pckong
December 10th, 2007, 05:25 AM
Hi,

I am testing some codes at the moment, but i need to use the library files provided by some other source. Is anyone know how to add my library files to ubuntu library, or create my own library? please help.
:popcorn:

meatpan
December 11th, 2007, 02:58 AM
Can you provide some more detail about what you want to do? Are you trying to compile a program that needs a special library? Do you want to make a library available via dynamic linking?

pckong
December 11th, 2007, 07:53 AM
Hi Meatpan,

Thanks for replying.
I am trying to compile some codes provided with a text book, Unix Network Programming by R. W. Stevens. All the codes provided are with its own header file <#include unp.h>. So I need to use the header file and library files (more than 50 library files).....

Anyway, I noticed that a file called "libunp.a" can be generated by "./configure". I thought it might be useful. So I have two options, one is to try "libtool" to link (probably dynamic linking) the library. but how to do it??

The other option is to copy all the files to gcc library. but where is the location of gcc library? I am not very good at linux...I am using gcc compiler (using gcc -Wall -ansi -o xyz xyz.c) by the way.

Thanks in advance!

meatpan
December 11th, 2007, 01:58 PM
Sounds like fun! I'm a big fan of that book ;)

When debugging a build process, I find it useful to explicitly separate the compilation and linking steps.

BTW, I assume you meant '#include <unp.h>' in your post below, as opposed to <#include unp.h>. Consider changing this to '#include "unp.h"' (quotes instead of brackets).

Now, for the compilation step, try:

gcc -Wall -ansi -c xyz.c

This will run the gcc compiler *without* trying to find a library file. The output should be a file named 'xyz.o'

Next, assuming that you built the libunp.a file during the make process, run
gcc -Wall -ansi -L<location of directory where libunp.a resides> -lunp -o xyz xyz.o
Notice the instruction to the compiler for linking the 'libunp' library (a bit confusing, because you need to strip off the 'lib' prefix from the actual library name). Also, the '-L' flag instructs the compiler to look in a particular directory for libunp.a. This is a handy flag to use when you are testing an installation.

Once the compilation and linking are working, there are some steps you can take to 'deploy' the libraries and headers, which will make future builds easier. This might have already been accomplished with the 'make install' portion. If so, the '-L<dir>' might be unnecessary, and you should replace the quotes with brackets in your #include statement.

pckong
December 11th, 2007, 09:59 PM
Hi,

The header file is #include "unp.h"
so it is not a library file... even though I try to compile with gcc -Wall -ansi -c xyz.c ....
as it can't skip header file, so I am still unable to create an object file xyz.o

if I use
gcc -Wall -ansi -L</home/pckong/UNP_book_src/unpv13e/lib> -o xyz xyz.c
where <directory> is the place stored unp.h file, but it gives me an error that
error: unp.h: No such file or directory
but i am sure the file is in that directory.

Thanks for your help again.

meatpan
December 12th, 2007, 12:30 PM
Hi,

as it can't skip header file, so I am still unable to create an object file xyz.o


Can you give some more details? I'm not understanding what you mean by skipping a header file. If the compiler cannot find a header file, add the '-I<path to directory of header file>'. Perhaps a posting of your error would be helpful.

pckong
December 13th, 2007, 06:49 AM
Hi Meatpan,

Thanks for your patiently teaching and sorry for my confusing post before. I am still learning programming.
Here is what I did, is it wrong? I feel so confused.

gcc -Wall -ansi -L/home/pckong/UNP_book_src/unpv13e/lib -c daytimetcpcli.c


I got the error message,
daytimetcpcli.c:1:17: error: unp.h: No such file or directory
daytimetcpcli.c: In function ‘main’:
daytimetcpcli.c:7: error: ‘MAXLINE’ undeclared (first use in this function)
daytimetcpcli.c:7: error: (Each undeclared identifier is reported only once
daytimetcpcli.c:7: error: for each function it appears in.)
daytimetcpcli.c:8: error: storage size of ‘servaddr’ isn’t known
daytimetcpcli.c:11: warning: implicit declaration of function ‘err_quit’
daytimetcpcli.c:13: warning: implicit declaration of function ‘socket’
daytimetcpcli.c:13: error: ‘AF_INET’ undeclared (first use in this function)
daytimetcpcli.c:13: error: ‘SOCK_STREAM’ undeclared (first use in this function)
daytimetcpcli.c:14: warning: implicit declaration of function ‘err_sys’
daytimetcpcli.c:16: warning: implicit declaration of function ‘bzero’
daytimetcpcli.c:18: warning: implicit declaration of function ‘htons’
daytimetcpcli.c:19: warning: implicit declaration of function ‘inet_pton’
daytimetcpcli.c:22: warning: implicit declaration of function ‘connect’
daytimetcpcli.c:22: error: ‘SA’ undeclared (first use in this function)
daytimetcpcli.c:22: error: expected expression before ‘)’ token
daytimetcpcli.c:25: warning: implicit declaration of function ‘read’
daytimetcpcli.c:27: warning: implicit declaration of function ‘fputs’
daytimetcpcli.c:27: error: ‘stdout’ undeclared (first use in this function)
daytimetcpcli.c:27: error: ‘EOF’ undeclared (first use in this function)
daytimetcpcli.c:33: warning: implicit declaration of function ‘exit’
daytimetcpcli.c:33: warning: incompatible implicit declaration of built-in function ‘exit’
daytimetcpcli.c:8: warning: unused variable ‘servaddr’
daytimetcpcli.c:7: warning: unused variable ‘recvline’

meatpan
December 13th, 2007, 02:39 PM
Hi Meatpan,
Thanks for your patiently teaching and sorry for my confusing post before. I am still learning programming.
Here is what I did, is it wrong? I feel so confused.


You are asking great questions, and every programmer has encountered these same challenges when learning how to compile code. That said, I think you are very close to getting your build up and running.

The 'unp.h: No such file or directory' is likely causing all of the other compilation problems.
Basically, the compiler cannot find a header file named 'unp.h'. You can give a compiler explict directions on where to look for a header file by using the '-I' flag (this is an upper-case 'i'). So, if unp.h is located in /home/pckong/tmp, adding '-I/home/pckong/tmp' will instruct the compiler to look in /home/pckong/tmp for header files.

Try running the same compilation command again, but this time specifiy the -I<directory where unp.h resides> flag.

pckong
December 13th, 2007, 08:07 PM
yes, it works!
gcc -Wall -ansi -I/home/pckong/UNP_book_src/unpv13e/lib -c daytimetcpcli.c
Thanks.

But, I got some new errors this time.
/home/pckong/UNP_book_src/unpv13e/lib/unp.h:286: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
/home/pckong/UNP_book_src/unpv13e/lib/unp.h:287: error: expected ‘)’ before ‘*’ token
/home/pckong/UNP_book_src/unpv13e/lib/unp.h:321: error: expected declaration specifiers or ‘...’ before ‘u_int’
/home/pckong/UNP_book_src/unpv13e/lib/unp.h:326: error: expected declaration specifiers or ‘...’ before ‘u_int’
/home/pckong/UNP_book_src/unpv13e/lib/unp.h:334: error: expected declaration specifiers or ‘...’ before ‘u_int’
/home/pckong/UNP_book_src/unpv13e/lib/unp.h:339: error: expected declaration specifiers or ‘...’ before ‘u_int’
/home/pckong/UNP_book_src/unpv13e/lib/unp.h:344: error: expected declaration specifiers or ‘...’ before ‘u_int’
/home/pckong/UNP_book_src/unpv13e/lib/unp.h:352: error: expected declaration specifiers or ‘...’ before ‘u_int’
/home/pckong/UNP_book_src/unpv13e/lib/unp.h:458: error: expected declaration specifiers or ‘...’ before ‘u_int’
So the problem must be from the header unp.h file, here is the relevant lines.

line286: u_char *inet_srcrt_init(int);
line287: void inet_srcrt_print(u_char *, int);
....
line321: int mcast_join(int, const SA *, socklen_t, const char *, u_int);
.....
line326: ..... const char *ifname, u_int ifindex);
line334: int mcast_set_if(int, const char *, u_int);
line339: void Mcast_join(int, const SA *, socklen_t, const char *, u_int);
line344: const char *ifname, u_int ifindex);
line352: void Mcast_set_if(int, const char *, u_int);
line458: void Sysctl(int *, u_int, void *, size_t *, void *, size_t);
the problem must be from declaration of u_int and u_char. I search internet for these two types, it seems they are from <sys/socket.h> library. so, how do i install sys/socket.h in Ubuntu?

stroyan
December 14th, 2007, 12:07 AM
/usr/include/sys/socket.h does define u_char, but not directly. it includes
/usr/include/sys/uio.h, which includes /usr/include/sys/types.h, which
defines u_char.

sudo apt-get install libc6-dev
will install all of those header files.

parmar.jr
May 31st, 2010, 01:13 PM
Hi pckong,

I am having the same problem. here is the detail


jr@ubuntu:/usr/src/unpv13e/intro$ gcc -Wall -ansi -I/usr/src/unpv13e/usr/src/unpv13e/lib -c daytimetcpcli.c
daytimetcpcli.c:1:17: error: unp.h: No such file or directory
daytimetcpcli.c: In function ‘main’:
daytimetcpcli.c:7: error: ‘MAXLINE’ undeclared (first use in this function)
daytimetcpcli.c:7: error: (Each undeclared identifier is reported only once
daytimetcpcli.c:7: error: for each function it appears in.)
daytimetcpcli.c:8: error: storage size of ‘servaddr’ isn’t known
daytimetcpcli.c:11: warning: implicit declaration of function ‘err_quit’
daytimetcpcli.c:13: warning: implicit declaration of function ‘socket’
daytimetcpcli.c:13: error: ‘AF_INET’ undeclared (first use in this function)
daytimetcpcli.c:13: error: ‘SOCK_STREAM’ undeclared (first use in this function)
daytimetcpcli.c:14: warning: implicit declaration of function ‘err_sys’
daytimetcpcli.c:16: warning: implicit declaration of function ‘bzero’
daytimetcpcli.c:18: warning: implicit declaration of function ‘htons’
daytimetcpcli.c:19: warning: implicit declaration of function ‘inet_pton’
daytimetcpcli.c:22: warning: implicit declaration of function ‘connect’
daytimetcpcli.c:22: error: ‘SA’ undeclared (first use in this function)
daytimetcpcli.c:22: error: expected expression before ‘)’ token
daytimetcpcli.c:25: warning: implicit declaration of function ‘read’
daytimetcpcli.c:27: warning: implicit declaration of function ‘fputs’
daytimetcpcli.c:27: error: ‘stdout’ undeclared (first use in this function)
daytimetcpcli.c:27: error: ‘EOF’ undeclared (first use in this function)
daytimetcpcli.c:33: warning: implicit declaration of function ‘exit’
daytimetcpcli.c:33: warning: incompatible implicit declaration of built-in function ‘exit’
daytimetcpcli.c:8: warning: unused variable ‘servaddr’
daytimetcpcli.c:7: warning: unused variable ‘recvline’
jr@ubuntu:/usr/src/unpv13e/intro$ gcc -Wall -ansi -I/usr/src/unpv13e/lib -c daytimetcpcli.c
In file included from daytimetcpcli.c:1:
/usr/src/unpv13e/lib/unp.h:286: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
/usr/src/unpv13e/lib/unp.h:287: error: expected ‘)’ before ‘*’ token
/usr/src/unpv13e/lib/unp.h:321: error: expected declaration specifiers or ‘...’ before ‘u_int’
/usr/src/unpv13e/lib/unp.h:326: error: expected declaration specifiers or ‘...’ before ‘u_int’
/usr/src/unpv13e/lib/unp.h:334: error: expected declaration specifiers or ‘...’ before ‘u_int’
/usr/src/unpv13e/lib/unp.h:339: error: expected declaration specifiers or ‘...’ before ‘u_int’
/usr/src/unpv13e/lib/unp.h:344: error: expected declaration specifiers or ‘...’ before ‘u_int’
/usr/src/unpv13e/lib/unp.h:352: error: expected declaration specifiers or ‘...’ before ‘u_int’
/usr/src/unpv13e/lib/unp.h:458: error: expected declaration specifiers or ‘...’ before ‘u_int'

any help will highly be appreciated.

-jr

annonymous
April 18th, 2011, 11:22 AM
Hey I know this thread is old but where do i download this library? I am starting to program linux sockets too. I am also using the same book. I compile and it says: time_server.c:1:17: fatal error: unp.h: No such file or directory
compilation terminated. So im guessing that i need the library. So where do i download it, where do i put it, and any other info that i need. Thanks

dpriest
January 14th, 2012, 09:49 PM
Hey I know this thread is old but where do i download this library? I am starting to program linux sockets too. I am also using the same book. I compile and it says: time_server.c:1:17: fatal error: unp.h: No such file or directory
compilation terminated. So im guessing that i need the library. So where do i download it, where do i put it, and any other info that i need. Thanks
http://www.ituring.com.cn/book/download/60498ad9-ede6-4023-a92b-04d47be23578