Operating System - HP-UX
1748269 Members
3716 Online
108760 Solutions
New Discussion юеВ

How Do I create a Shared library

 
SOLVED
Go to solution
Vinay_19
Occasional Advisor

How Do I create a Shared library

I am ion HP-UX 64 bit Itanium 11.23i ,rx2600.
I would like to create a shared library from the C Objects as well as C++.

I am using bundled C compiler that comes with the operating system and gcc compiler version 3.4.2 from GNU.

Let's say I have two C programs. One with one function and another with functions.

I would to create a shared library for the above.

Similarly Let's say I have two C++ programs like above How do I create a shared library.

Let's say I have

a.c with functions void func1() ,void func2()
b.c with functions void func3()

I want to create a shared library from the above as libab.so or libab.sl




Thank you,
Any help appreciated,
Vinay

7 REPLIES 7
ranganath ramachandra
Esteemed Contributor
Solution

Re: How Do I create a Shared library

the bundled c compiler is not very useful for application development. you'll need to use gcc or buy HP's ansi C and/or aCC (C++) compiler(s).

cc/aCC : (cc = ansi C compiler, not bundled)
cc -b a.c b.c -o libab.so
aCC -b a.c b.c -o libab.so

the gcc line is probably:
gcc -fpic -shared a.c b.c -o libab.so
 
--
ranga
[i work for hpe]

Accept or Kudo

Vinay_19
Occasional Advisor

Re: How Do I create a Shared library

But this seems to create a 32-bit shared library while I am on a 64 bit Itanium machine.Is there an option in gcc which would create a 64-bit shared library .

Thank you,
vinay
ranganath ramachandra
Esteemed Contributor

Re: How Do I create a Shared library

i guess you need to use gcc's "-mlp64" flag.

http://www.hp.com/go/gcc

for cc/aCC it is "+DD64"
 
--
ranga
[i work for hpe]

Accept or Kudo

H.Merijn Brand (procura
Honored Contributor

Re: How Do I create a Shared library

You forgot a very important option on the cc command (+Z for cc, -fPIC for gcc, which you /did/ mention), create sharable objects to enable shared libs

# cc -O +Z -c file_a.c
# cc -O +Z -c file_b.c
# ld -b -o files.sl file_a.o file_b.o
# cc -O +Z -o test -L. -lfiles test.c

# gcc -O -fPIC -c file_a.c
# gcc -O -fPIC -c file_b.c
# ld -b -o files.sl file_a.o file_b.o
# gcc -O -fPIC -o test -L. -lfiles test.c

I don't have an Itanium here, but I've build perl on on of HP's testdrive systems, where I noted that Itanium, other than pa-risc, can use gcc to build both 32bit (default) and 64bit (-mlp64) objects. On pa-risc machines you need two different compilers for 32 and 64bitness

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
ranganath ramachandra
Esteemed Contributor

Re: How Do I create a Shared library

HP's ELF (PA64 and IA) compilers emit PIC code by default, that is why i left out "+z".

getting them to emit non-PIC code is not easy.

also, PA32 cc understands "-b" means "+z" - PA32 aCC doesnt, they are fixing that.

building c++ libraries by using ld directly is discouraged. it leads to problems most of the time.
 
--
ranga
[i work for hpe]

Accept or Kudo

H.Merijn Brand (procura
Honored Contributor

Re: How Do I create a Shared library

Thank you for this additional info!

no points please

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Vinay_19
Occasional Advisor

Re: How Do I create a Shared library

Thank you for responding , I will try all of your suggestions and award points