Operating System - HP-UX
1821981 Members
5709 Online
109638 Solutions
New Discussion юеВ

static linking of libraries using gcc on hpux 11

 
SOLVED
Go to solution
mango_1
Frequent Advisor

static linking of libraries using gcc on hpux 11

hello all! I tried to link statically an archive file using the following command:

cc .... -Wl,-shared,-aarchive -L${SRCROOT}/obj -lexample ...

but I encounter an error as follows:
/usr/ccs/bin/ld: Unsatisfied symbols:
main (first referenced in /usr/lib/libc.a(start_what.o)) (code)

Can somebody tell me what could be the problem and the solution? thanks
7 REPLIES 7
H.Merijn Brand (procura
Honored Contributor
Solution

Re: static linking of libraries using gcc on hpux 11

To create a static library, you will have to use ar. For the creation of dynamic libraries, it depends if you are using 32bit gcc, which uses HP's ld, and requires the -b option, or a 64bit gcc, which - depending of the port - can use either GNU ld, or HP's ld.

Building static libraries with ld option -shared (only valid for GNU ld), is a bit silly.

FWIW, shared libraries need shared objects. gcc -fPIC, or cc +Z

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
mango_1
Frequent Advisor

Re: static linking of libraries using gcc on hpux 11

thanks for the reply. I already have an archive library. The thing is I want to statically link to it. The program also has shared libraries and static libraries to link to. How should I go about linking?

thanks!

Gregory Fruth
Esteemed Contributor

Re: static linking of libraries using gcc on hpux 11

First of all, do you have a main program?
The error message suggests that there
is no main program.

Secondly, are you sure "-Wl,-shared,-aarchive"
is what you typed? That would pass the
options "-shared -aarchive" to ld. My
version of ld doesn't recognize the "-shared"
flag. It would see this is "-s -h ared".

Perhaps you should try "cc ...
-Wl,-aarchive -L${SRCROOT}/obj
-lexample ...". This forces ld to use
static linking. If the desired library
is not available in archive form ld will
complain that it can't find the library.

HTH




Gregory Fruth
Esteemed Contributor

Re: static linking of libraries using gcc on hpux 11

Just read your later post.

Normally you just let ld determine which
form of a library to use. If you tell it
to link with "-lfoo", ld first tries to find
a shared lib called "libfoo.sl", and if
that can't be found it tries to find
an archive lib called "libfoo.a".

If for some reason you want to force ld to
use one form or the other, you can do that
on a lib by lib basis using:

cc myprog.c -Wl,-aarchive -lfoo -Wl,-ashared -lbar

This forces ld to use libfoo.a and libbar.sl.
Gregory Fruth
Esteemed Contributor

Re: static linking of libraries using gcc on hpux 11

P.S. It is my understanding that on IPF
(aka Itanium aka IA64) archive libraries
are deprecated or at least discouraged.
For example, libc is not available in
archive form.

I don't know if this is just while HP-UX
is in transition to IPF or if it is a
permanent direction.
ranganath ramachandra
Esteemed Contributor

Re: static linking of libraries using gcc on hpux 11

use -l:libexample.a.

"-shared" is not a linker option/flag. the parameter to '-a' can be 'archive' / 'shared' / 'archive_shared' / 'shared_archive' / 'default' (and *has* to appear *after* '-a').
 
--
ranga
hp-ux 11i v3[i work for hpe]

Accept or Kudo

H.Merijn Brand (procura
Honored Contributor

Re: static linking of libraries using gcc on hpux 11

If you *are* using gcc, and cc is thusly a link to gcc, just pass '-shared' or '-static' to gcc, and it should know how to handle the ld flags.

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn