Operating System - HP-UX
1833618 Members
4261 Online
110062 Solutions
New Discussion

Re: invalid magic number using shared lib, explanations please

 
Florent_1
Occasional Contributor

invalid magic number using shared lib, explanations please

Hi there,
I'm using cc in hp-ux 11.11 to build a shared library lib1.sl. that works well.

Then I still use cc to build another library lib2.sl, including lib1. I get an error:
/usr/ccs/bin/ld: /home/dev/resources/lib1.sl: Not a valid object file (invalid magic number)

What does that mean exactly?
What compilation options should I use on CC to correctly build the first library?

Thanks for all answers.

Florent.
5 REPLIES 5
Steve Lewis
Honored Contributor

Re: invalid magic number using shared lib, explanations please

When you say lib2.sl will include lib1.sl, do you mean that lib1.sl calls functions in lib2.sl or that the two libraries are to be put together in one file.

If you want them to be two separate libraries, then dont include lib1.sl in the command to compile/link the program - you will have to explicitly attach the 2nd shared library in your program, as well as the first.

If you want the two libraries in one .sl then cc -c lib1.c (creates an object file lib1.o) and then cc -b lib2.c lib1.o -o lib-both.sl

.sl files are not the same as .o files.

I hope I understood the question.
Florent_1
Occasional Contributor

Re: invalid magic number using shared lib, explanations please

The correct way is that lib1 is included in lib2: code contained in lib2 calls functions defined in lib1.

But what does "invalid magic number" means?

Thanks.
Florent.
Steve Lewis
Honored Contributor

Re: invalid magic number using shared lib, explanations please

I think I should have tested it before I wrote that response, since I dont get that error! 10 lashes with the cat-o'nine tails for me, sorry.

It lets me cc -o testprog test.c test2.sl
But using nm on the file testprog doesn't show me the functions in test2.sl.

It seems to me that maybe your lib1.sl was built on another architecture. Were they both compiled on the same machine, with the same options (CCOPTS/LDOPTS) and +DA..?

You could try compiling everything using +DA_PORTABLE but that wouldn't be the most efficient way through.

Use chatr on both object files to see what they are.
Steve Lewis
Honored Contributor

Re: invalid magic number using shared lib, explanations please

The man page 'man magic' will tell you about magic numbers.
Essentially the magic number defines how a program is loaded in memory and whether it is kept there for others to use (i.e. same code, different data for different processes).

Maybe one was exec magic and the other share-magic or demand-loaded or something, where the two are incompatible.
ranganath ramachandra
Esteemed Contributor

Re: invalid magic number using shared lib, explanations please

i suspect the command "file lib1.sl" will say something like
lib1.sl: PA-RISC2.0 shared executable

you should use the '-b' option of cc to build the first and the second libraries:

1. cc -b 1.c -o lib1.sl
2. cc -b 2.c ./lib1.sl -o lib2.sl
(or)
cc -b 2.c -L. -l1 -o lib2.sl
 
--
ranga
hp-ux 11i v3[i work for hpe]

Accept or Kudo