[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:21 Dec 2004 22:09:21 -0000 
Subject:Problems with linux dynamic linker and separately compiled modules 
From:A . Sloman 
Volume-ID: 

This may be related to the problem with blas and lapack libraries
reported previously.

I am using vision code written in C and invoked from Pop11, developed
and tested under solaris on a Sun at Sussex University by David Young.
It works on Solaris but we get strange problems with the dynamic linker
on linux on a PC.

David reduced the problem to a simple test case.

There are two files foo.c defining a function foo, and a file baz.c
defining function baz, where foo calls baz.

We do the following to compile the files into shareable libaries, then
later dynamically link the files into a running pop11 process, then try
to run foo inside pop11. It should call baz, but instead causes a crash
with 'baz' undefined.

1. Compile file foo.c to produce shareable foo.so

	gcc -o foo.so -fpic -shared foo.c

2. Compile file baz.c to produce shareable baz.so

	gcc -o baz.so -fpic -shared baz.c

3. Dynamically link both .so files into pop11, using external pop11
loading mechanisms that work on a Sun and seem to work with other
libraries on linux.

Create Pop11 file testlink.p


    exload foobaz ['foo.so' 'baz.so']
        foo(1):int;
    endexload;

    exacc foo(101) =>

4. Call the external procedure foo, by running the file:

	pop11 testlink.p

System crashes with message:
	relocation error: ./foo.so: undefined symbol: baz

However on Solaris it all works as expected. Is there
some difference in the compiler/linker conventions?

We can avoid the crash by first compiling with the -c option to create
two .o files, then combine them to one .so file and simply link that
file into pop11 using exload.

But we would like to have the flexibility to link sharable
libraries in different combinations.

I've scanned manuals for gcc and ld on linux and cannot find
any clue.

Has anyone ever met this sort of problem on linux, i.e. dynamically
linking two separately compiled libraries fails to make a connection
between a symbol used in one and defined in the other?

I have heard of people who don't use pop11 having similar 'undefined
symbol' problems with the blas and lapack mathematical libraries, but
don't know if the problems were ever resolved.

It is just possible that there is something wrong with how pop11
externally loads sharable libraries in linux, but that seems unlikely
given that, for example, it allows all the X11 code to be dynamically
loaded successfully.

Is there some sort of compile-time switch to gcc which says that when
foo is invoked it will have to resolve baz in another library also
dynmically linked.

Thanks.
Aaron