octal9
octal9

Reputation: 368

How to resolve shared library location when it changes between compile & run time?

I have the following:

g++ $(LD_OPTS) -o lib/foo.so lib/bar.o lib/qaz.o ../path/to/foodependency.so

It and foo are both being built here (assume foodependency has already been built by the makefile previously). The end result looks something like this, during build:

project
---libFoo
------lib
---------foo.so
---libFooDependency
------lib
---------foodependency.so

However, during runtime, both foo.so and foodependency.so are in the same directory, bar:

bar
---foo.so
---foodependency.so

This layout during runtime cannot be changed. But now as a result, ldd foo.so returns the following: ../path/to/foodependency.so => not found

How can I resolve this difference?

Upvotes: 1

Views: 170

Answers (1)

Employed Russian
Employed Russian

Reputation: 213456

How can I resolve this

There are several ways.

  1. Rename foodependency.so to libfoodependency.so, and use -L../path/to -lfoodependency when linking, or
  2. Use -L../path/to -l:foodependency.so when linking, or
  3. When linking foodependency.so, add -Wl,--soname=foodependency.so and use your original link line.

Upvotes: 1

Related Questions