1

question

How can I compile a shared library linking with version-independent boost shared library? My cmakelists.txt is like as follows

find_package(Boost REQUIRED COMPONENTS serialization)
...
target_link_libraries(_omplpy PRIVATE ${Boost_LIBRARIES} ${otherdeps})

And, after compiling this, I checked dependency by ldd command and it shows that only the dependency of boost libraries are too specific (seems that version 1.71.0 is specified, though other libraries does not care about the minor version)

h-ishida@stone-jsk:~/python/ompl-python-thin$ ldd build/_omplpy.cpython-38-x86_64-linux-gnu.so 
    linux-vdso.so.1 (0x00007ffd34ca9000)
    libboost_serialization.so.1.71.0 => /lib/x86_64-linux-gnu/libboost_serialization.so.1.71.0 (0x00007f208012f000)
    libboost_filesystem.so.1.71.0 => /lib/x86_64-linux-gnu/libboost_filesystem.so.1.71.0 (0x00007f2080111000)
distir  libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f20800ee000)
    libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f207ff0c000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f207fdbd000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f207fda0000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f207fbae000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f20812a6000)

The problem is, boost libraries version are different for different ubuntu distributions, thus my compiled shard library _omplpy cannot be used in different distribution.

context (maybe unrelated)

I am trying to distribute a python package where a shared library linked with boost stuff is inside. Because python wheel (binary version of package) is only python-version (like 2.7, 3.8), os (mac, windows, ldistirinux), and archtecture dependent (like x86_64, aarch64), it seems impossible to distribute packages dependent on specific ubuntu distribution. For your information, the package mentioned is https://github.com/HiroIshida/ompl-thin-python and corresponding CMakeLists.txt is here https://github.com/HiroIshida/ompl-thin-python/blob/master/CMakeLists.txt

orematasaburo
  • 1,207
  • 10
  • 20
  • 1
    I decided to build static boost library with -fPIC option and compile the target library with linking that. It's much easier. – orematasaburo Jan 02 '23 at 16:01

1 Answers1

2

How can I compile a shared library linking with version-independent boost shared library?

You can't, because the different boost libraries are not ABI-compatible. If you somehow succeeded in linking your library with "version-independent boost", the result would be a runtime crash.

Read about the reasons for external library versioning here.

P.S.

I decided to build static boost library with -fPIC option and compile the target library with linking that.

That is much easier, but unless you are very careful with symbol hiding, this approach will cause runtime crashes (if you are lucky) as soon as someone tries to use your python package in program which uses a different version of boost libraries (due to symbol collision and ABI incompatibility). And if you are unlucky, symbol collision may cause other very hard to find bugs.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • 2
    Mind you, it would result in a runtime crash **iff you're lucky**. It could also lead to thermo-nuclear war or your puppy being cut into 3 unequal pieces. Excellent point about symbol visibility too. – sehe Jan 02 '23 at 19:46
  • Thanks. I'm not sure if you got what I try to mean, but I meant build boost like this https://github.com/HiroIshida/ompl-thin-python/blob/master/release/Dockerfile#L22-L26 and compile with `set(Boost_USE_STATIC_LIBS ON)` cmake option. Because boost is statically linked into, I think there is no problem even though sameone uses different version from mine. Am i right? – orematasaburo Jan 02 '23 at 21:25
  • @orematasaburo "I think there is no problem" -- sadly you are mistaken. See e.g. this answer https://stackoverflow.com/a/62897619/50617 – Employed Russian Jan 02 '23 at 23:27