building shared libraries on linux with SunStudio
Hi,
I installed the sunstudio-compilers on my system (SuSE 10.0/x86-64) and try to build a shared library.
For my (c++-)library I use autoconf/automake, so I hoped it to be trouble-free, but it is not. I configured my library with:
./configure CC=cc CXX=CC CFLAGS=-fast CXXFLAGS=-fast -D_GNU_SOURCE
(I needed this -D_GNU_SOURCE to have pthread_rwlock_*).
The compiler run fine, but the linker does not produce any output. I guess the command, which should have created the library is:
/bin/sh ../libtool --tag=CXX --mode=link CC -fast -D_GNU_SOURCE-o libcxxtools.la -rpath /usr/local/lib -lpthread -version-info 3:1:0 base64stream.lo cgi.lo dlloader.lo hdstream.lo hirestime.lo httpreply.lo httprequest.lo iniclass.lo log.lo md5.lo md5stream.lo multifstream.lo net.lo pollclass.lo query_params.lo tcpstream.lo tee.lo thread.lo udp.lo udpstream.lo xmltag.lo iconvstream.lo ../libltdl/libltdlc.la -lnsl
It creates a src/libcxxtools.la and symbolic links src/.libs/libcxxtools.so and src/.libs/libcxxtools.so.3, but no shared library src/.libs/libcxxtools.so.3.0.1, where the links point to. Is there any chance to get automake running with sunstudio?
[1197 byte] By [
Tntnet] at [2007-11-26 7:25:42]

# 1
libtool problem is that it has embedded knowledge about compiler options, and it is platform-dependant.
libtool knows that it should use [i]-G[/i] to link shared library with SunStudio on Solaris.
It has no clue about existance of SunStudio on Linux.
Anyway, if you are compiling with SunStudio you should always link with SunStudio (cc, CC or f90).
Thus proper configure line should include LD=CC for C++, LD=cc for C programs.
If you use default linker (ld) it will fail to resolve dependancies specific to SunStudio compiler.
Thats what happens in your case.
However even if you specify LD=CC it will not do shared libraries for the cause mentioned about - when configuring libtool tries to figure out how to build shared library and deciding not to build it at all.
You can get out with LD=cc (as our cc driver supports gnu-style [i]-shared[/i] option).
Though you will have to specify all the SunStudio C++-specific link dependancies manually.
Another option is to modify libtool script. Which version do you use?
regards,
__Fedor.
SFV at 2007-7-6 19:13:47 >

# 2
> libtool problem is that it has embedded knowledge
> about compiler options,
It is not libtool -- its autoconf.
> Another option is to modify libtool script. Which
> version do you use?
I think the right place to fix it would be in autoconf's PIC/shared stub.
Thanks,
Roman.
# 3
I tried now to make a simple shared-library without libtool first to learn, how to do it with SunStudio, but still failed. Here is, what I've done:
I created a c-file func.c:
#include <stdio.h>
int func()
{
printf("%s\n", "Hello World!");
}
Compiled with: cc -c func.c
Link with: cc -o libfunc.so -G func.c
I get this message:
/usr/bin/ld: func.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
func.o: could not read symbols: Bad value
Sounds like I need to pass -fPIC to the compiler: cc -c -fPIC func.c
I get this:
cc: Warning: illegal option -fPIC
Is this a linker-option?
Next I tried to do compile and link in one step: cc -o libfunc.so -G func.o
Again -fPIC is missing.
And with -fPIC: cc -o libfunc.so -G -fPIC func.c
The compiler warns again about illegal option.
Can you tell me, how I can build just a simple shared library with SunStudio?
# 4
> Sounds like I need to pass -fPIC to the compiler: cc -c -fPIC func.c
> cc: Warning: illegal option -fPIC
> Is this a linker-option?
That message issused by gnu-ld tells about a gcc option.However we do not support gnu style options yet.
In SunStudio position independent code is generated by [b]-KPIC[/b] option.
regards,
__Fedor.
SFV at 2007-7-6 19:13:47 >

# 5
Thank you - that brings me further. I can build my simple shared library now.
Back to my c++-library. I try to build it now without libtool. I can build the library, but when I try to link a program against it I got:
/usr/local/sun/sunstudiomars/prod/lib/amd64/ld: md5sum: hidden symbol `stat' in /usr/lib64/libc_nonshared.a(stat.oS) is referenced by DSO
/usr/local/sun/sunstudiomars/prod/lib/amd64/ld: final link failed: Nonrepresentable section on output
"md5sum" is the programname I try to build. I have again no clue, what that means, but I'm sure, you can help;-)
Regards
Tommi M鋕italo