We help IT Professionals succeed at work.

C shared object library

loriwang7310
loriwang7310 asked
on
How do I create a C shared object library on this type of architecture?

SunOS machine1 5.7 Generic_106541-12 sun4u sparc SUNW,Ultra-4

I think I would use some switch on the c compiler.  I think it is -G but
when I tried that it created a .o file.  I need a .so file to use as a library
of external procedures to call from Oracle PL/SQL code.  The compiler
I'm using is this:

 /opt/SUNWspro/bin/cc -c filename.c -G -DMACHINE1 -Xc -xcg92

this gives me filename.o not filename.so - Is that the same thing? I just
need to rename the .o file to .so?

Comment
Watch Question

CERTIFIED EXPERT

Commented:
ld -shared -B dynamic -o libfilename.so filename.o

Author

Commented:
I am getting an error:

make libname.so
/opt/SUNWspro/bin/cc -c filename.c -DMACHINE1 -Xc -xcg92
ld -shared -B dynamic -o libname.so filename.o
ld: fatal: option -h and building a dynamic executable are incompatible
ld: fatal: Flags processing errors
*** Error code 1
make: Fatal error: Command failed for target `libname.so'

Am I maybe using the ld program:
machine1>which ld
/usr/ucb/ld

I looked in

machine1>pwd
/opt/SUNWspro/SC5.0/bin

for an ld program and all I found was ild program.  I tried that ild but
that didn't work either and it seemed to have called ld anyway:

machine1>make all
make tvlUtilities.so
/opt/SUNWspro/bin/cc -c filename.c -DDBSDEVMACHINE -Xc -xcg92
/opt/SUNWspro/SC5.0/bin/ild -shared -B dynamic -o libname.so filename.o
ild: calling ld to finish link -- license not available
ld: fatal: option -h and building a dynamic executable are incompatible
ld: fatal: Flags processing errors
*** Error code 1
make: Fatal error: Command failed for target `libname.so'


Your assistance is appreciated.
CERTIFIED EXPERT
Commented:
oops, please remove the  -shared  option, it's for linux, sorry.

Author

Commented:
The plot thickens.

That works but now I'm getting something else:
machine1>make all
make libname.so
/opt/SUNWspro/bin/cc -c filename.c -DMACHINE1 -Xc -xcg92
ld -B dynamic -o libname.so filename.o
Undefined                       first referenced
 symbol                             in file
atof                                filename.o  (symbol belongs to implicit dep)
atoi                                filename.o  (symbol belongs to implicit dep)
toupper                             filename.o  (symbol belongs to implicit dep)
getPass                             filename.o
exit                                filename.o  (symbol belongs to implicit dep)
ItFill                              filename.o
malloc                              filename.o  (symbol belongs to implicit dep)
ItGetLine                           filename.o
RfcInstallStructure                 filename.o
sscanf                              filename.o  (symbol belongs to implicit dep)
ItFree                              filename.o
ItCreate                            filename.o
ItAppLine                           filename.o
RfcCall                             filename.o
RfcLastError                        filename.o
RfcConnect                          filename.o
strchr                              filename.o  (symbol belongs to implicit dep)
free                                filename.o  (symbol belongs to implicit dep)
strcmp                              filename.o  (symbol belongs to implicit dep)
ItDelete                            filename.o
RfcReceive                          filename.o
memset                              filename.o  (symbol belongs to implicit dep)
strcpy                              filename.o  (symbol belongs to implicit dep)
RfcClose                            filename.o
memcpy                              filename.o  (symbol belongs to implicit dep)
strlen                              filename.o  (symbol belongs to implicit dep)
ld: fatal: Symbol referencing errors. No output written to libname.so
*** Error code 1
make: Fatal error: Command failed for target `libname.so'

Whoops, I guess I forgot to tell you some things.  I'm seeing some of the
stuff that belongs to the SAP RFC library where I am making some calls
but I am also (puzzling) seeing memcpy and strlen, those are C library
calls.

In the filename.c I am making calls to a SAP RFC library.  The switches
to that are:

LD_LIBRARY_PATH starts as:
/opt/SUNWspro/lib:/usr/openwin/lib:
/usr/dt/lib::/usr/local/src/oracle/product/8.1.7/lib


XLDPATHFLAG = -lrfc -lsocket -lnsl -ldl -lm -lw
LD_LIBRARY_PATH = $LD_LIBRARY_PATH:/usr/local/sap/lib

I compile filename.c like this:

filename.o: tvlUtilities.c ${COMDIR}/TravelDB.h
        /opt/SUNWspro/bin/cc -c filename.c -DMACHINE1 -Xc -xcg92

So when creating the end result, the exe file, I do this:

upd_invoices.exe:    upd_invoices.o ${XOBJS}
        make -f ${COMDIR}/proc.mk EXE=upd_invoices.exe OBJS="upd_invoices.o \
       ${XOBJS}" LDPATHFLAG="${XLDPATHFLAG}" build

In my XOBJS is filename.o, the object file.  So they have this executable that
runs from UNIX but now they want the utilities in filename.o in a C shared library
to call from PL/SQL.

I guess, well this is pretty obvious, do you think I need to actually read
the man page on ld?[HA!]

Or maybe I have a path wrong:

machine1>echo $PATH
/usr/xpg4/bin:/usr/ucb:/usr/ccs/bin:/usr/local/bin:/usr/bin:/etc:/usr/sbin:
/p00/tvx/bin:/opt/NSCPcom:/sbin:/usr/local/etc:/usr/lib:
/usr/opt/SUNWmd/sbin:/usr/bin::/usr/local/bin/perl5.00502:
.:/usr/local/src/oracle/product/8.1.7/bin:
/p00/tvx/bin:/p00/tvx/dev/script

You probably know the answer.  Your help is appreciated.

Author

Commented:
ahoffmann,

It is working now.  I had to use the -G option and
I had to extract the object files from the rfc library
and add them to the line that makes the .so file.

 /usr/ccs/bin/ld -B dynamic -G -lsocket -lnsl -ldl -lm -lw -o libname1.so
 filename.o cpictlib.o rfcilib.o util1.o util2.o

I will give you the points.  Thanks for pointing me in the
right direction!

CERTIFIED EXPERT

Commented:
well done, that was what I wanted to post as next comment ..

Explore More ContentExplore courses, solutions, and other research materials related to this topic.