Need help linking (Sun Workshop 6 CC)

Hi list,

I am experiencing a problem with exporting functions in a shared library that I am building with Sun Workshop. I am compiling my C code using the following format:

/opt/SUNWspro/WS6U2/bin/cc -c -mt -xO4 -Kpic -s -misalign -xCC -xchar -xipo -D_REENTRANT -I./INCLUDE -I./PLATFORM/INCLUDE -o file1.o file1.c

I am linking my archives with the following command:

/opt/SUNWspro/WS6U2/bin/CC -xar -o libfiles1.a file1.o file2.o file3.o

Then I am building my shared object library with the following command:

/opt/SUNWspro/WS6U2/bin/cc -dy -Bdynamic -M lib-SOLARIS.def -G -h libfiles.so.1.1.1 -o libfiles.so.1.1.1 libfiles1.a libfiles2.a libfiles3.a file9.o

Notice that when I am linking the shared library I am linking archives, objects and maybe even other shared libraries.

The build works but I am getting undefined symbols in the shared libraries.

Anything obviously wrong here?

Thanks.

[959 byte] By [securehella] at [2007-11-26 12:39:58]
«« Sudoku
»» Object...
# 1
There's a rule of thumb: if at least one object file was compiled with C++ compiler, CC, you _have_ to link with CC. Try this, it's probably linking with cc that's causing unresolved symbols.
MaximKartasheva at 2007-7-7 16:10:45 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2
Also, there is a number of compiler flags that should be specified both on compile and link command line.One of those is -xipo, which you did you to compile your .o's.You can find a full list of those "specific" options in a user guide.regards,__Fedor.
SFVa at 2007-7-7 16:10:45 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3

[code]

/opt/SUNWspro/WS6U2/bin/cc -dy -Bdynamic -M lib-SOLARIS.def -G -h libfiles.so.1.1.1 -o libfiles.so.1.1.1 libfiles1.a libfiles2.a libfiles3.a file9.o

[/code]

I don't think the above will place your .a in .so

Only the .o which are required will be extracted and put in the .so

This might be the reason.

Vibhor_Agarwala at 2007-7-7 16:10:45 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 4
Use following comans in order to make archive libraryar cr nameof archieve.a objects-Riaj
koresha@123a at 2007-7-7 16:10:45 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 5

The solution that worked for me was to add -z rescan to the link command. I also added -z allextract but I don't know that it was necessary. Turns out I had some recursive dependancies that were not resolving during the link as I had it.

Thanks for the suggestions, though. Hope this helps someone in the future.

job317a at 2007-7-7 16:10:45 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 6

Just for the record, I think -z allextract is the magic option.

It causes all the contents of the archive libraries to get put

into the shared library regardless of whether their symbols are

referenced by the initial code preceding the archive library

on the link line.

--chris

ChrisQuenellea at 2007-7-7 16:10:45 > top of Java-index,Development Tools,Solaris and Linux Development Tools...