Operating System - HP-UX
1753482 Members
4532 Online
108794 Solutions
New Discussion юеВ

Re: Creating a shared object

 
SOLVED
Go to solution
devshlom
Regular Advisor

Creating a shared object

Hi,
I have to create a shared object (so) on HP-UX.
I already have a Makefile that does it for all the other unix platforms (aix, linux, solaris)
1. what should to make it work on HP?
2. can one of you give me a working and small example for a Makefile that creates a shared object?

tx,
shlom
29 REPLIES 29
Fabien GUTIERREZ
Frequent Advisor

Re: Creating a shared object

on pa-risc shared library are designed as .sl files and on integrity servers as .so files
you can refer to this external link to find examples of compile and linking options

http://www.franz.com/support/documentation/current/doc/foreign-functions.htm#ff-on-hp-1
Dennis Handly
Acclaimed Contributor

Re: Creating a shared object

On HP-UX these are called shared libraries.
Here is the Linker Online Help:
http://docs.hp.com/en/11782/LinkerOnliinehelp0709/creatingandusinglibraries.htm

Creating shlibs is pretty simple:
libfoo.so: foo.o
$(CC) -b -o $@ foo.o

foo.o: foo.c
$(CC) -c foo.c

If you are on PA, change to ".sl" and add +z to the compile line.
devshlom
Regular Advisor

Re: Creating a shared object

hi dennis,
tx again for your answers.

Sorry for the beginner questions - I still new to this platforms...
1. how do I know if I'm working on PA? when I run uname -a I get: "HP-UX hpux B.11.23 U 9000/800 3697136004 unlimited-user license"

2. When I add +Z to the compile command I get: "gcc: +Z: No such file or directory"

3. In your example:
- you put "-b" what this option stands for?
- should I used also "-shared"?

As you see, I'm a little confused here - if you make it simple for me I will be grateful.

my gcc is: (gcc -v)
Using built-in specs.
Target: hppa2.0w-hp-hpux11.23
Configured with: ../gcc/configure
Thread model: posix
gcc version 4.2.2


tx!!!
shlom
Dennis Handly
Acclaimed Contributor

Re: Creating a shared object

>1. how do I know if I'm working on PA? when I run uname -a I get: "HP-UX hpux B.11.23 U 9000/800

This is PA. Otherwise it says ia64 for Integrity.

>2. When I add +Z to the compile command I get: "gcc: +Z: No such file or directory"
>my gcc is:

Ah, you are using a foreign devil compiler.
You need -fpic.

>- you put "-b" what this option stands for?
>- should I used also "-shared"?

-b is the linker and HP's compiler option to create shlibs.
Yes, replace by -shared for gcc.
devshlom
Regular Advisor

Re: Creating a shared object

so,
after we both know what I'm working on,pls see the reason I got confused
when I use the following:
"$(CC) -shared -fpic -o $@ $(OBJ) ...", I get this weird msg:
/usr/ccs/bin/ld: CODE_ONE_SYM fixup to non-code subspace in file /home/s/import/so/TestSo/TestSo/debug/HPUX-Risc/test.o - shared library must be position independent. Use +z or +Z to recompile.
collect2: ld returned 1 exit status

so? how can I prevent this?

tx
Dennis Handly
Acclaimed Contributor

Re: Creating a shared object

>ld: CODE_ONE_SYM fixup to non-code subspace in file test.o - shared library must be position independent. Use +z or +Z to recompile.
>how can I prevent this?

Was test.o compiled with -fpic?
devshlom
Regular Advisor

Re: Creating a shared object

tx dennis,


yes - the object did compile with the -fpic!!!
1. I succeeded create the sample so (the small one) - but the big one still doesn't work (even with the -fPIC)

2. another question:
after knowing how to generate a shared object, what is the standard for its extension? should I use ".sl" instead of ".so"

tx
Dennis Handly
Acclaimed Contributor
Solution

Re: Creating a shared object

>yes - the object did compile with the -fpic!!

That's not what the linker says. So either you didn't or gcc is broken.
If you want to attach a copy of test.o, I can look at it.

>1. but the big one still doesn't work

The above linker error? Or something else?

>2. what is the standard for its extension? should I use ".sl" instead of ".so"

On PA you use .sl. On IPF you use .sl.
devshlom
Regular Advisor

Re: Creating a shared object

Hi again,

1. After I added -fpic to both compilation and linkage the test shared object was created!!!

2. The big program that I mentioned before is my real shared object (not the tester)that I have to create - here is the error I get:
/usr/ccs/bin/ld: Invalid loader fixup in text space needed in output file for symbol "CClassName::~CClassName()" in input file "/home/s/lib_somelib.a(Someobject.o)"
collect2: ld returned 1 exit status
this is the first time I get such error - any idea? is it something to do with the extenal lib that is linked with the shared object? any idea?

3. when I run file on the tester shared object I get the following result:
"libtest.so:PA-RISC2.0 shared library -not stripped" - I think it's ok - what do say?

4. according to what you said before, I will have to change the extesion to "sl" - don't I?


tx a lot!
shlom