Unix Programming - Link error in Solaris

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > May 2006 > Link error in Solaris





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Link error in Solaris
googler

2006-05-23, 1:17 am

I have a Makefile that I use to compile in Linux. Using the same
Makefile to compile the same code in Solaris 10 gives me error in the
link stage.

g++ -shared -Wl,-soname,libstorelib.so.1 -o libstorelib.so.2.5-1
slcommon.o sldebug.o slaenregister.o slaenprocessor.o sltopology.o
slsolaris.o -L/usr/lib -lpthread -ldl
ld: warning: option -o appears more than once, first setting taken
ld: fatal: file libstorelib.so.1: open failed: No such file or
directory
ld: fatal: File processing errors. No output written to
libstorelib.so.2.5-1
collect2: ld returned 1 exit status
*** Error code 1
dmake: Fatal error: Command failed for target `libstorelib.so.2.5-1'

How shall I modify the Makefile to compile in Solaris? From 'man ld' I
saw that -soname option is not present. I am using g++ version 3.4.3.

I am pasting the relevant part from my Makefile below.

.....
.....
LIB_NAME = libstorelib.so.$(LIB_VER)-$(LIB_VER_QUALIFIER)
OBJS=slcommon.o sldebug.o slaenregister.o slaenprocessor.o sltopology.o
slsolaris.o
LIBS=-L/usr/lib -lpthread -ldl

all: storelib
storelib: /usr/lib/libstorelib.so
/usr/lib/libstorelib.so: $(LIB_NAME)
rm -f /usr/lib/libstorelib.so*
cp $(LIB_NAME) /usr/lib/
ldconfig
ln -sf /usr/lib/libstorelib.so.1 /usr/lib/libstorelib.so
$(LIB_NAME): $(OBJS)
g++ -shared -Wl,-soname,libstorelib.so.1 -o $(LIB_NAME) $(OBJS)
$(LIBS)
.....
.....

I understand that the ldconfig needs to be replaced by crle, but for
now the error occurs even before that.

Any help will be greatly appreciated. Some pointer to sample Makefile
(in Solaris) might be of help too.

Paul Pluzhnikov

2006-05-23, 1:17 am

"googler" <pinaki_m77@yahoo.com> writes:

> I have a Makefile that I use to compile in Linux. Using the same
> Makefile to compile the same code in Solaris 10 gives me error in the
> link stage.


As it should. You are passing GNU-ld specific option (-soname)
to solaris ld, which treats it as if '-s -oname libstorelib.so.1'

> How shall I modify the Makefile to compile in Solaris? From 'man ld' I
> saw that -soname option is not present.


Use appropriate solaris ld switch (-h).

> I am using g++ version 3.4.3.


That's irrelevant.

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
Casper H.S. Dik

2006-05-23, 7:16 am

"googler" <pinaki_m77@yahoo.com> writes:

>g++ -shared -Wl,-soname,libstorelib.so.1 -o libstorelib.so.2.5-1
>slcommon.o sldebug.o slaenregister.o slaenprocessor.o sltopology.o
>slsolaris.o -L/usr/lib -lpthread -ldl
>ld: warning: option -o appears more than once, first setting taken
>ld: fatal: file libstorelib.so.1: open failed: No such file or
>directory
>ld: fatal: File processing errors. No output written to
>libstorelib.so.2.5-1
>collect2: ld returned 1 exit status
>*** Error code 1
>dmake: Fatal error: Command failed for target `libstorelib.so.2.5-1'


>How shall I modify the Makefile to compile in Solaris? From 'man ld' I
>saw that -soname option is not present. I am using g++ version 3.4.3.



The -Wl,-soname,libstorelib.so.1 option is parsed by the Solaris linker
as:
-s -o name libstorelib.so.1

hence the complaint about -o appearing more than once and libstorelib.so.1
being a file not found.

You want to use:

-Wl,-h,libstorelib.so.1

Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
googler

2006-05-24, 1:20 am

Casper H.S. Dik wrote:
> "googler" <pinaki_m77@yahoo.com> writes:
>
>
>
>
> The -Wl,-soname,libstorelib.so.1 option is parsed by the Solaris linker
> as:
> -s -o name libstorelib.so.1
>
> hence the complaint about -o appearing more than once and libstorelib.so.1
> being a file not found.
>
> You want to use:
>
> -Wl,-h,libstorelib.so.1
>
> Casper


Thanks. The -h option worked fine. A couple of related questions on the
same Makefile. This is what it looks like.

all: storelib
storelib: /usr/lib/libstorelib.so
/usr/lib/libstorelib.so: $(LIB_NAME)
rm -f /usr/lib/libstorelib.so*
cp $(LIB_NAME) /usr/lib/
ldconfig
ln -sf /usr/lib/libstorelib.so.1 /usr/lib/libstorelib.so
$(LIB_NAME): $(OBJS)
g++ -shared -Wl,-soname,libstorelib.so.1 -o $(LIB_NAME)
$(OBJS) $(LIBS)

Since I cannot use ldconfig in Solaris, I am trying to use crle
instead. ldconfig when executed will create a link called
libstorelib.so.1 (which is the soname) for $(LIB_NAME) and will also
update the directory cache. I am wondering if crle can do the same
thing. From what I read on manpage, it appears that it won't create any
link for soname. Then shall I use the ln command myself to create this
link?

Here is what it looks like after my changes.
/usr/lib/libstorelib.so: $(LIB_NAME)
rm -f /usr/lib/libstorelib.so*
cp $(LIB_NAME) /usr/lib/
ln -sf /usr/lib/$(LIB_NAME) /usr/lib/libstorelib.so.1 #added
crle -u #added
ln -sf /usr/lib/libstorelib.so.1 /usr/lib/libstorelib.so

Is this OK? Will the -u option with crle update the directory cache
too?

Also, on trying to play with crle command, I saw that this command
"crle -i /lib -i /usr/lib" (for adding entries from the specified
directories into the directory cache) adds entries from the directories
/usr/openwin/lib and /usr/dt/lib too to the cache, as evident from a
subsequent "crle" command. I didn't understand why this should happen.

Casper H.S. Dik

2006-05-24, 7:16 am

"googler" <pinaki_m77@yahoo.com> writes:


>Thanks. The -h option worked fine. A couple of related questions on the
>same Makefile. This is what it looks like.


>all: storelib
>storelib: /usr/lib/libstorelib.so
>/usr/lib/libstorelib.so: $(LIB_NAME)
> rm -f /usr/lib/libstorelib.so*
> cp $(LIB_NAME) /usr/lib/
> ldconfig
> ln -sf /usr/lib/libstorelib.so.1 /usr/lib/libstorelib.so
>$(LIB_NAME): $(OBJS)
> g++ -shared -Wl,-soname,libstorelib.so.1 -o $(LIB_NAME)
>$(OBJS) $(LIBS)


I would suggest that you also add a "chmod" in there somewhere and link
before you start installing. (Otherwise the lib is gone if the
link fails)

I'm somewhat surprised at both the copy and the "g++ -o $(LIB_NAME)"

>Since I cannot use ldconfig in Solaris, I am trying to use crle
>instead. ldconfig when executed will create a link called
>libstorelib.so.1 (which is the soname) for $(LIB_NAME) and will also
>update the directory cache. I am wondering if crle can do the same
>thing. From what I read on manpage, it appears that it won't create any
>link for soname. Then shall I use the ln command myself to create this
>link?


If you install a library in /usr/lib, then there's nothing else you
need to do. It will be found.

Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com