Operating System - HP-UX
1748201 Members
3085 Online
108759 Solutions
New Discussion юеВ

static and shared library options for aCC

 
SOLVED
Go to solution
Ram Regar
New Member

static and shared library options for aCC

Hi,
I have

module1 should be built as static library.
module2 should be a shared library and it should like module1 statically.

module3 is an executable which dynamically links to module2 library.

I am looking for aCC command options to achieve this goal.

It should work on 64 and 32 bit OS.

Thanks,
Ram
7 REPLIES 7
Dennis Handly
Acclaimed Contributor

Re: static and shared library options for aCC

>module1 should be built as static library.

(The correct HP-UX terminology is archive lib.)
What OS and architecture are you using?

>I am looking for aCC command options to achieve this goal.

aCC -c foo1.c foo2.c
ar -rv libmod1.a foo1.o foo2.o

aCC -c +z foo3.c foo4.c
aCC -b o libmod2.so foo3.o foo4.o -L . -lmod1

aCC -c foo5.c foo6.c
aCC -o module3 foo5.o foo6.o -L . -lmod2

For Integrity see:
http://docs.hp.com/en/14487/libs.htm
Ram Regar
New Member

Re: static and shared library options for aCC

Thank you for ur response.

I have this box.
-bash-3.2$ uname -a
HP-UX ramregar-hp11i B.11.23 U ia64 1869050062 unlimited-user license
-bash-3.2$

I want to build 32-bit and 64-bit builds on the same box.
Thanks,
Ram
Dennis Handly
Acclaimed Contributor

Re: static and shared library options for aCC

>I want to build 32-bit and 64-bit builds on the same box.

The default is 32 bit or you can use +DD32.
And +DD64 for 64 bit.
Ram Regar
New Member

Re: static and shared library options for aCC


Thank you so much for your support so far. Please do continue until I finish this.

Module1 a static library.
aCC -O -g0 -O2 +Oopenmp +z +DD64 -b -Wl,-ashared -D_HPUX -D__LP64__ -DPIC -I/build/jdk/include -lunalign -o/build/rel/lib/static/libmodule1.a *.cpp *.c

Module2 a dynamic library which statically links the Module1
aCC -O -g0 -O2 +Oopenmp +z +DD64 -b -n -v -D_HPUX -D__LP64__ -I/build/jdk/include -Wl,-L/build/rel/lib/static/ -lmodule1 -o/build/rel/lib/libmodule.so *.cpp *.c

Module3 a dynamic library which statically links the module1
aCC -O -g -O2 +Oopenmp +z +DD64 -b -v -ashared -D_HPUX -D__LP64__ -L/build/rel/lib/static/ -lmodule1 -o/build/rel/lib/libmodule3.so *.cpp

Module4 an executable which dynamically links module2. Module2 loads Module3 at runtime.
aCC +DD64 +Oopenmp -I/build/clients/include -L/build/rel/lib/ -lmodule2 -lrt -lunalign -o/build/bin/module4 *.cpp


aCC version:
aCC: HP C/aC++ B3910B A.06.23 [May 18, 2009]


Problem:
When I run module4
/usr/lib/hpux64/dld.so: Unsatisfied data symbol '_ZTV14MyListener' in load module '../lib/libmodule2.so'.
Killed

I looked in library with nm command. Here is the output.

build@hp16 /build/rel/lib $ nm -D libmodule2.so | grep MyListener
[4825] | 4611686018430846112| 288|FUNC |GLOB |0| .text|_Z17createNewListenerP14MyListenerPP9_listenerPFvP12_space_eventPvES6_
[4748] | 4611686018431064384| 416|FUNC |GLOB |0| .text|_ZN6CSpace5startEP14MyListenerP11CBrowserDef
[2880] | 0| 0|OBJT |GLOB |0| UNDEF|_ZTV14MyListener
[1065] | 4611686018431074480| 112|FUNC |LOCAL|0| .text|__sinit_MyListener_cpp_
[1064] | 0| 0|FILE |LOCAL|0| ABS|MyListener.cpp
build@hp16 /build/rel/lib $

I would appreciate your help. Please do review compiler options and suggest me the changes.

Regards,
Ram Regar
Dennis Handly
Acclaimed Contributor
Solution

Re: static and shared library options for aCC

>module1 a static library.

Again, please use the correct terminology. There are only archive and shared libs.
In this case, this is a shared lib since you used -b and not ar(1).

>aCC -O -g0 -O2 +Oopenmp +z +DD64 -b -Wl,-ashared -D__LP64__ -lunalign -o /build/rel/lib/static/libmodule1.a *.cpp *.c

There is no need for both -O and +O2. There is no need to define -D__LP64__ or -Wl,-ashared, they are set by the driver or the default. Also, why bother with +Oopenmp?
Also, you should NOT use -b with libmodule1.a. Rename it to libmodule1.so.

>module2 a dynamic library which statically links the module1
>aCC -O -g0 -O2 +Oopenmp +z +DD64 -b -n -v -Wl,-L/build/rel/lib/static/ -lmodule1 -o /build/rel/lib/libmodule.so *.cpp *.c

The output should be libmodule2.so
Remove useless -n. Also remove "-Wl," before -L.

>module4 an executable which dynamically links module2. module2 loads module3 at runtime.
>aCC +DD64 +Oopenmp -lmodule2 -lrt -lunalign -o/build/bin/module4 *.cpp

And also has module1 as a dependent shlib.

dld.so: Unsatisfied data symbol _ZTV14MyListener load module ../lib/libmodule2.so
>I looked in library with nm command.

Where should it be defined? Where have you defined the class MyListener and the first non-inline virtual function?
Ram Regar
New Member

Re: static and shared library options for aCC

Thank you Dennis Handly I appreciate your help. Your quick help has been very helpful to me. Thank you.
Ram Regar
New Member

Re: static and shared library options for aCC

Dennis Handly is a great help. He definitely deserve 100/100.