linking with .so on linux

Hello,
I'm trying to port a program to linux. I have few projects: one of them is an executable program; others are dynamic libraries (.dll or .so). I need to link dynamic libraries with the main executable.
On windows I have to use import library ('dllname.a') in linking to link with 'dllname.dll'. I need to do the same thing on linux. My question is: do I need an import library when linking with shared objects (.so)? Or maybe I can simply include .so file in linking?

Thanks for help.
when linking do:
 
g++ -o prog prog.o -ldllname

If libdllname.so is not in the system directory then add its directory to the library path:

 
g++ -o prog prog.o -L/path/to/my/library/folder -ldllname

I can't get it working because ld can't find my libraries

My project's directory structure is like this:

folder/src/lib_sources
folder/src/app_sources
folder/bin <-- binaries and .so libraries are stored in this folder


I set libraries path to -L /../../bin/ and I'm linking with llibname but ld doesn't figure out that libname.so is in bin directory,

If I link with ../../bin/libname.so it compiles fine but I can't run my program because of runtime errors
/bin/app: error while loading shared libraries: ../../bin/libname.so: cannot open shared object file: No such file or directory


How can I fix this?

Last edited on
man gcc for more information about the -L and -l parameters. Once it compiles, the executable still needs to find the shared library at runtime. One way is to set the LD_LIBRARY_PATH environment variable.
You seem to be using an absolute path notation when you supply a relative path. If your path is relative then you should not have a leading '/'

Maybe try:
 
-L../../bin/ 

Or specify the full path.

At runtime you can set LD_LIBRARY_PATH=../../bin if you need to.
Last edited on
Topic archived. No new replies allowed.