General
cancel
Showing results for 
Search instead for 
Did you mean: 

How compile a shared library ??? Help !!!!

Lorein
Occasional Advisor

How compile a shared library ??? Help !!!!

Hi

I have a progrma in C and I want to compile as a shared library.

My program name is shell.c and this is the code

#include
#include
#include

void sh(char *);

void sh( char *cmd )
{
int num;

num = system(cmd);
}


This is the correct way to compile a shell library ?


$ cc -b -c shell.c
$ ld -r -o shell.so shell.o

I'll call this library from an Oracle 10g procedure


11 REPLIES
Dennis Handly
Acclaimed Contributor

Re: How compile a shared library ??? Help !!!!

Is this for PA or IPF?
$ cc -b +z shell.c
Lorein
Occasional Advisor

Re: How compile a shared library ??? Help !!!!

Is Itanium.
Lorein
Occasional Advisor

Re: How compile a shared library ??? Help !!!!

Let me add more detial.
I hava a HP-UX itanium 12.23 and the datbase is oracle 10g

When I compile the C programm I can create the .so (shared library) and .o files. But when I tried to call it from the procedure in oracle I receive an error. I think maybe i'm not compiling in the correct way.
I receive the next errors

ora-06520: PL/SQL: Error loading external library
ora-06522 '/oracle/SA_scripts/scripts/shell.so' is not a valid load module. Bad magic
number
Dennis Handly
Acclaimed Contributor

Re: How compile a shared library ??? Help !!!!

>But when I tried to call it from the procedure in oracle I receive an error. I think maybe i'm not compiling in the correct way.

Oracle is 64 bit so your shlib must be compiled the same way.
$ cc -b +DD64 +z shell.c -o shell.so

>is not a valid load module. Bad magic number

Right I get the same thing:
dlopen error: './libdebug.so' is not a valid load module: Bad magic number
$ file a.out libdebug.so
a.out: ELF-32 executable object file - IA64
libdebug.so: ELF-64 shared object file - IA64
Lorein
Occasional Advisor

Re: How compile a shared library ??? Help !!!!


Do you know what else I need to do?

What is the correct way to compile a shared library?

Thanks
Dennis Handly
Acclaimed Contributor

Re: How compile a shared library ??? Help !!!!

>Do you know what else I need to do?
>What is the correct way to compile a shared library?

Unless you have a new error message or a different question, my answers are the same.

What does "file /oracle/SA_scripts/scripts/shell.so" show?
Lorein
Occasional Advisor

Re: How compile a shared library ??? Help !!!!


Now I fixed the error of magic number , and I compile the library like you did:
$ cc -b +DD64 +z shell.c -o shell.so

My question now is how can I link this file? in order to create a shell.o

thanks!
Dennis Handly
Acclaimed Contributor

Re: How compile a shared library ??? Help !!!!

>My question now is how can I link this file? in order to create a shell.o

This compiles and links and creates shell.so in one step.
If you need multiple steps:
cc -c +z sources ...
cc -b -o shell.so objects
Dennis Handly
Acclaimed Contributor

Re: How compile a shared library ??? Help !!!!

It might be helpful to look at the documentation:
http://docs.hp.com/en/14487/libs.htm
http://docs.hp.com/en/14640/OnlineHelp/linkhelp.html

You can also use:
cc +help
ld +help
Lorein
Occasional Advisor

Re: How compile a shared library ??? Help !!!!

Thanks let me try...
Dennis Handly
Acclaimed Contributor

Re: How compile a shared library ??? Help !!!!

If you are happy with the answers you got, please read the following about assigning points:
http://forums.itrc.hp.com/service/forums/helptips.do?#33