简体   繁体   中英

Linux linking a shared object

I am linking an so, that depends on libmxml.so. However I have no rights install libmxml.so.

So thats what I am doing

gcc -shared -m32 -o ServiceProvider.so ServiceProvider.o -L ../../../../system/addonlibs/ -lmxml -lpthread

ldd shows me

ldd ServiceProvider.so 
    libmxml.so.1 => not found
    libpthread.so.0 => /lib/libpthread.so.0 (0x40026000)
    libc.so.6 => /lib/libc.so.6 (0x40046000)

the second try was

gcc -shared -m32 -o ServiceProvider.so ServiceProvider.o ../../../../system/addonlibs/libmxml.so -lpthread

and still ldd shows me

ldd ServiceProvider.so 
    libmxml.so.1 => not found
    libpthread.so.0 => /lib/libpthread.so.0 (0x40026000)
    libc.so.6 => /lib/libc.so.6 (0x40046000)

Consequently, ldd does not find the library, since I only have "libmxml.so", but no "libmxml.so.1". How do I get rid of this ".1" suffix? Why is it comming?

When you link with a dynamic library, you should not do :

gcc -shared -m32 -o ServiceProvider.so ServiceProvider.o ../../../../system/addonlibs/libmxml.so -lpthread

Instead, make sure that /yourpath/system/addonlibs (you should use the full path instead of a relative one) is in you LIBRARY_PATH . Then change you link command.

export LIBRARY_PATH=/yourpath/system/addonlibs:$LIBRARY_PATH
gcc -shared -m32 -o ServiceProvider.so ServiceProvider.o -lmxml -lpthread

You can also write that:

gcc -shared -m32 -o ServiceProvider.so ServiceProvider.o -L/yourpath/system/addonlibs -lmxml -lpthread

However, to run your program, you will need to have your library path in LD_LIBRARY_PATH .

If you have issues with .so and .so.1 stuff, then rename your .so to .so.1 and make a symlink from .so.1 to .so .

Edit:

If you do objdump -p libmxml.so | grep SONAME objdump -p libmxml.so | grep SONAME you will probably get libmxml.so.1 . It is where you get the libmxml.so.1 identifier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM