Operating System - HP-UX
1824012 Members
3773 Online
109667 Solutions
New Discussion юеВ

Where to put C header (.h) and library (.sl,.a) files

 
km4hr
Occasional Contributor

Where to put C header (.h) and library (.sl,.a) files

What are the appropriate directories for installing third party C program development files? I'm using HPUX 11.0.
7 REPLIES 7
A. Clay Stephenson
Acclaimed Contributor

Re: Where to put C header (.h) and library (.sl,.a) files

The header files go into each source file.

e.g. in foo.c

#include
#include

int main()
{

}

------------------------------------------

A common practice is to list all the needed header files in a local header file, local.h

#include
#include

------------------------------------------

and then simply include the one file, local.h, in all of your .c files,
e.g.

#include "local.h"

Now the slared and arcive libraries are not included until the link phase although they can be included in the normal cc command line with the source files.

e.g.

To compile foo1.c and foo2.c (which presumably have #include "local.h" lines in them) and link with /usr/lib/dummy1.sl and local library mylib.a and create an executable file, foo, something like this should suffice:


cc foo1.c foo2.c -ldummy1 mylib.a -o foo

You could also do this in two-steps like this:

cc -c foo1.c foo2.c

this will create foo1.o and foo2.o

You then link these:
cc foo1.o foo2.o -ldummy1 mylib.a -o foo

Of course, the preferred way to do this is to create a makefile. Look for a few examples of makefiles because any serious development should use them.
If it ain't broke, I can fix that.
Steven Schweda
Honored Contributor

Re: Where to put C header (.h) and library (.sl,.a) files

It depends. Files used only within the
third-party product normally stay with the
source. Files which need to be available for
other uses are often installed under
"/usr/local" (like "/usr/local/include" for
the header files, "/usr/local/lib" for the
object libraries, and so on), but the user
normally gets to choose this directory when
the product is installed.

In some places, "/opt" is popular instead of
"/usr/local".
km4hr
Occasional Contributor

Re: Where to put C header (.h) and library (.sl,.a) files

How do I tell where the linker searches for library and header files by default? If there's a place where third party stuff like that will be found without automatically I might want to put header and library files there.
thanks.
Steven Schweda
Honored Contributor

Re: Where to put C header (.h) and library (.sl,.a) files

> How do I tell where the linker searches for
> library and header files by default?

The linker doesn't search for header files.
Compilers search for header files.

"man aCC" or "man cc". Look for "-I".
"aCC +help" or "cc +help"?

"man ld". Look for "+b", LD_LIBRARY_PATH,
LPATH, RPATH, and SHLIB_PATH. "ld +help"?
Dennis Handly
Acclaimed Contributor

Re: Where to put C header (.h) and library (.sl,.a) files

>Steven: LPATH ...

Instead of using LPATH, use -L path instead.

>automatically I might want to put header and library files there.

There is no default locations for your libs and headers. I don't think you should put user headers and libs in /usr/include/ and /usr/lib/. (Though it maybe reasonable to put shlibs in /usr/lib/.)
Steven Schweda
Honored Contributor

Re: Where to put C header (.h) and library (.sl,.a) files

Just to be clear, I don't advocate using any
of the *PATH variables, but looking for them
in the "man" output helps to find the better
methods and the explanations.

And I also would advise not adding one's own
files to "/usr/include" or "/usr/lib".
A. Clay Stephenson
Acclaimed Contributor

Re: Where to put C header (.h) and library (.sl,.a) files

It appears that I misread your question. Generally, applications I've developed and deployed adopt this convention:

Choose AND DOCUMENT an environment variable for your application, e.g. MYAPP.

The executables are installed in ${MYAPP}/bin, the header files go in ${MYAPP}/include, and the libraries are installed in ${MYAPP}/lib. It's then an easy matter to have your makefiles change the -I path for include files and the set the path for libraries.
If it ain't broke, I can fix that.