td icon indicating copy to clipboard operation
td copied to clipboard

td doesn't install shared libraries despite configuring with TD_INSTALL_SHARED_LIBRARIES=ON

Open yurivict opened this issue 8 months ago • 6 comments

It only installs static libs, with one exception of libtdjson:

lib/libtdactor.a
lib/libtdapi.a
lib/libtdclient.a
lib/libtdcore.a
lib/libtddb.a
lib/libtde2e.a
lib/libtdjson.so
lib/libtdjson_private.a
lib/libtdjson_static.a
lib/libtdmtproto.a
lib/libtdnet.a
lib/libtdsqlite.a
lib/libtdutils.a

Version: 1.8.48 (hash b8b08b0) FreeBSD 14.2

yurivict avatar May 09 '25 15:05 yurivict

libtdjson is the only library that is supposed to be shared. The options TD_INSTALL_STATIC_LIBRARIES and TD_INSTALL_SHARED_LIBRARIES can be used to avoid installation of static or shared libraries. See https://github.com/tdlib/td/pull/3081 for the history, why the options were introduced.

levlam avatar May 09 '25 16:05 levlam

The linked issue says that static libs are built for the sake of projects that embed tdlib.

But on FreeBSD in the ports we avoid static libs because port/package dependencies are hard to track when they install static libs.

Is there a way to add a non-default option to always build all shared libs?

yurivict avatar May 09 '25 16:05 yurivict

Removing the STATIC keywords from all add_library instructions and making BUILD_SHARED_LIBS to depend on the option TD_INSTALL_SHARED_LIBRARIES does the trick.

yurivict avatar May 11 '25 19:05 yurivict

Yes. You don't even need to make BUILD_SHARED_LIBS dependent on TD_INSTALL_SHARED_LIBRARIES. Just specify BUILD_SHARED_LIBS separately during cmake configuration. The option is supposed to be provided by the user of cmake, not by the CMakeLists.txt itself.

This works only because GCC/clang export everything from shared libraries by default, which significantly increase binary size, can expose some internal functions and data, and have no chance to work on Windows. In the case of TDLib having the libraries as shared libraries provides no advantages given that they don't have stable interface and can't be updated independently.

But if installing of shared libraries only is a required policy and can't be avoided, then I can only point to https://lore.kernel.org/lkml/CAHk-=whs8QZf3YnifdLv57+FhBi5_WeNTG1B-suOES=RcUSmQg@mail.gmail.com/ and propose to patch all CMakeLists.txt files and remove 'STATIC' from all library definitions on the package manager side.

levlam avatar May 11 '25 20:05 levlam

Just specify BUILD_SHARED_LIBS separately during cmake configuration.

This doesn't work because every add_library instruction has the STATIC argument hardcoded.

yurivict avatar May 12 '25 06:05 yurivict

You said

Removing the STATIC keywords from all add_library instructions and making BUILD_SHARED_LIBS to depend on the option TD_INSTALL_SHARED_LIBRARIES does the trick.

I commented that the second part isn't needed.

levlam avatar May 12 '25 08:05 levlam