Connecting Tech Pros Worldwide Help | Site Map

unresolved symbol with shared library

Oliver
Guest
 
Posts: n/a
#1: Jul 19 '05
Hi,

I have a problem with a shared library of mine. I compile the *.o
files and then generate the .so lib with:
cc -shared libjava_vrpn.so *.o
When I then run my program I get an error for an unresolved symbol.

The symbols it's looking for are in another library called libvrpn.a,
but for some unknown reason the compiler does not uses this library
when I tell him to used.
I compile the libs as before and then try:
cc -shared -L../sgi_irix.../ -lvrpn -o libjava_vrpn.so *.o
The compiler then comes with a waring that the libvrpn.a is not used
for resolving any symbol and my application is still complaining about
the first unresolved symbol.

When use the command nm to check the library's I can see that the
sybol could be resolved by using the libvrpn.a. What do I do wrong?
What is it that I have to do to make use of the other library?


thanks
Oliver
Rolf Magnus
Guest
 
Posts: n/a
#2: Jul 19 '05

re: unresolved symbol with shared library


Note that your problem is off-topic here. This newsgroup is only about
the C++ programming language as defined by the ISO, not about problems
with specific compilers/linkers.

Oliver wrote:
[color=blue]
> Hi,
>
> I have a problem with a shared library of mine. I compile the *.o
> files and then generate the .so lib with:
> cc -shared libjava_vrpn.so *.o
> When I then run my program I get an error for an unresolved symbol.
>
> The symbols it's looking for are in another library called libvrpn.a,
> but for some unknown reason the compiler does not uses this library
> when I tell him to used.
> I compile the libs as before and then try:
> cc -shared -L../sgi_irix.../ -lvrpn -o libjava_vrpn.so *.o
> The compiler then comes with a waring that the libvrpn.a is not used
> for resolving any symbol and my application is still complaining about
> the first unresolved symbol.
>
> When use the command nm to check the library's I can see that the
> sybol could be resolved by using the libvrpn.a. What do I do wrong?[/color]

What happens is that the linker goes through the files you provided in
the order you specified. It maintains a list of unresolved symbols
internally. When it comes to -lvrpn, it sees that this archive cannot
be used to resolve any symbols (since there are no unresolved symbols
yet), throws it away and goes on. Later, your object files come and
need some external symbols (from that archive), which now are added to
the list of unresolved symbols. Those are never resolved, since there
is nothing after the .o files, so you get a linking error. Try
providing the archive _after_ the .o files.

Attila Feher
Guest
 
Posts: n/a
#3: Jul 19 '05

re: unresolved symbol with shared library


Oliver wrote:[color=blue]
> I compile the libs as before and then try:
> cc -shared -L../sgi_irix.../ -lvrpn -o libjava_vrpn.so *.o
> The compiler then comes with a waring that the libvrpn.a is not used
> for resolving any symbol and my application is still complaining about
> the first unresolved symbol.[/color]

OFF TOPIC!

cc -shared -o libjava_vrpn.so *.o -L../sgi_irix.../ -lvrpn

AFAIK this is the problem, the lib has to be specified after the objects.
Please next time post to the newsgroup dedicated to your compiler/linker:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9

--
Attila aka WW


Oliver Otto
Guest
 
Posts: n/a
#4: Jul 19 '05

re: unresolved symbol with shared library


Sorry about posting this here and thanks for your help.

Rolf Magnus wrote:
[color=blue]
>Note that your problem is off-topic here. This newsgroup is only about
>the C++ programming language as defined by the ISO, not about problems
>with specific compilers/linkers.
>
>Oliver wrote:
>
>
>[color=green]
>>Hi,
>>
>>I have a problem with a shared library of mine. I compile the *.o
>>files and then generate the .so lib with:
>>cc -shared libjava_vrpn.so *.o
>>When I then run my program I get an error for an unresolved symbol.
>>
>>The symbols it's looking for are in another library called libvrpn.a,
>>but for some unknown reason the compiler does not uses this library
>>when I tell him to used.
>>I compile the libs as before and then try:
>>cc -shared -L../sgi_irix.../ -lvrpn -o libjava_vrpn.so *.o
>>The compiler then comes with a waring that the libvrpn.a is not used
>>for resolving any symbol and my application is still complaining about
>>the first unresolved symbol.
>>
>>When use the command nm to check the library's I can see that the
>>sybol could be resolved by using the libvrpn.a. What do I do wrong?
>>
>>[/color]
>
>What happens is that the linker goes through the files you provided in
>the order you specified. It maintains a list of unresolved symbols
>internally. When it comes to -lvrpn, it sees that this archive cannot
>be used to resolve any symbols (since there are no unresolved symbols
>yet), throws it away and goes on. Later, your object files come and
>need some external symbols (from that archive), which now are added to
>the list of unresolved symbols. Those are never resolved, since there
>is nothing after the .o files, so you get a linking error. Try
>providing the archive _after_ the .o files.
>
>
>[/color]

Juan Antonio Domínguez Pérez
Guest
 
Posts: n/a
#5: Jul 19 '05

re: unresolved symbol with shared library


Oliver wrote:
[color=blue]
> Hi,
>
> I have a problem with a shared library of mine. I compile the *.o
> files and then generate the .so lib with:
> cc -shared libjava_vrpn.so *.o
> When I then run my program I get an error for an unresolved symbol.
>
> The symbols it's looking for are in another library called libvrpn.a,
> but for some unknown reason the compiler does not uses this library
> when I tell him to used.
> I compile the libs as before and then try:
> cc -shared -L../sgi_irix.../ -lvrpn -o libjava_vrpn.so *.o
> The compiler then comes with a waring that the libvrpn.a is not used
> for resolving any symbol and my application is still complaining about
> the first unresolved symbol.
>
> When use the command nm to check the library's I can see that the
> sybol could be resolved by using the libvrpn.a. What do I do wrong?
> What is it that I have to do to make use of the other library?[/color]

I think that an .a library cannot be resolve at run-time: it is an
static library. You must remove the -shared flag?

Ron Samuel Klatchko
Guest
 
Posts: n/a
#6: Jul 19 '05

re: unresolved symbol with shared library


o.otto@reading.ac.uk (Oliver) wrote in message news:<f5f070bf.0310130249.4996a53a@posting.google. com>...[color=blue]
> Hi,
>
> I have a problem with a shared library of mine. I compile the *.o
> files and then generate the .so lib with:
> cc -shared libjava_vrpn.so *.o
> When I then run my program I get an error for an unresolved symbol.
>
> The symbols it's looking for are in another library called libvrpn.a,
> but for some unknown reason the compiler does not uses this library
> when I tell him to used.
> I compile the libs as before and then try:
> cc -shared -L../sgi_irix.../ -lvrpn -o libjava_vrpn.so *.o
> The compiler then comes with a waring that the libvrpn.a is not used
> for resolving any symbol and my application is still complaining about
> the first unresolved symbol.
>
> When use the command nm to check the library's I can see that the
> sybol could be resolved by using the libvrpn.a. What do I do wrong?
> What is it that I have to do to make use of the other library?[/color]

Okay, since you post this in comp.lang.c++, I'm just going to take a
wild guess here.

By any chance are the function in libvrpn.a compiled as C functions
but the header file for that library does not surround the prototypes
with extern "C" { }?

I haven't used SGI much, but on Solaris you will see something like
this:

From the linker:
Unresolved external:
void foo(int)

From nm:
foo ...

While they seem the same they are not. The first one includes C++
type safe linkage while the second one is plain old C linkage.

samuel
Closed Thread