views:

23

answers:

2

I have a shared object (abc.so) that i built after linking it to a bunch of libs (.a and .so) files. Now this abc.so just exposes 3 functions.

Now i am writing a console application on linux that uses this abc.so to invoke those function. When i try to build that application,

I get a bunch of - "Undefined reference to 'xxxxxxx' " errors. Now these references go to so's that abc.so is depending on abd even go deeper for references within those so's.

I am not sure why this happens. SHouldnt it load those at the run time? Atleast thats what i thought (coming froma windows/MSVC background).

Kindly help me on this one.

+1  A: 

You still need to link against the library file, but you tell the linker that the symbols should be loaded at runtime from a shared library by linking with the .so file. What does your linker command line look like?

Also check your LD_LIBRARY_PATH. If your shared library isn't in one of the standard locations, like /usr/lib, then you need to do:

export LD_LIBRARY_PATH=pathToDirWithYourSharedLibrary:$LD_LIBRARY_PATH

If you don't, you'll get runtime errors.

lrm
+2  A: 

You have to link your application with a reference to all the shared objects (.so) your application depends on. You do not need to relink with statically included archives (.a)

If abc.so is built with a.so, b.so and c.a you will have to link your application with abc.so, a.so and b.so.

When your application is correctly linked, you also must be sure that it can find the shared objects. You can use 'ldd myapp' to list shared objects dependencies.

my2c

neuro