GCC and libraries

GCC and libraries

Post by vent.. » Wed, 16 Oct 1996 04:00:00

I'm having a little trouble working out what libraries to link against
when compiling C programs. The basic command, according to my
reference book is gcc -o file file.C, but the book also says that if,
for example, the file includes math.h, the command should be gcc -o
file file.C -lm. This works, but my question is: I can't seem to find
any guidelines as to what, in general, to use after the -l switch. For
example, if my program includes malloc.h, should I still use -lm? If
not, what?

Please spare a few moments to answer this.


1. library that depends on a library, C, gcc, ar

Using linux+gcc+static libraries(ar) and a project in C, what's the
best way to make a library that includes or "encapsulates" another

For example, let's say I am making a C library called FOO, which
depends on another library I made called BAR (where "depends on" means
that FOO #includes "BAR.h" during compilation and links with -lBAR
when FOO's test apps are linked).

When /usr/local/lib/libFOO.a and /usr/local/include/FOO.h are properly
installed, I want users to be able to #include "FOO.h" and link with
-lFOO, without knowing anything about BAR.

however, my library-making command is simply

ar r libFOO.a FOO.o

What I want it to do is something like

ar r libFOO.a FOO.o libBAR.a  <--- bad syntax meant only for illustration

so the BAR library, and associated .o objects, are somehow
"encapsulated" inside libFOO.a.  However, I understand that ar is only
meant to append together a bunch of .o files, so my syntax is
obviously wrong.  But I hope it hints at the idea I'm trying to get

Currently, users have to link against -lFOO and -lBAR in order to use
FOO at all.  To me, this is ugly since it from the user's perspective,
all they should need to know about is FOO.  So, what's the best
approach to my problem?

2. Apache SSL

3. Matrox Mystique ands X.

4. HELP: Netscape Communicator 4.04 and RH 5.0 freezes once in a while..

5. libraries libraries libraries

6. help

7. Slackware 1.2.0 gcc library problem

8. Question: errno in shared library?

9. Xa.o library? (GCC installation) Oh, please, help!

10. gcc and gethostbyname: where is the library

11. Compiling with gcc, libraries missing? workarounds?y

12. GCC language support library question.

13. Compiling with gcc, libraries missing???