kesari
kesari

Reputation: 576

C++ templated functions inside .so file

Libraries like Boost which provide C++ templates for functions and data structures are made available through a .so file. I read that .so files contain machine code that only needs to be loaded into the memory at runtime.

It seems to me that machine instructions also have to have some form of template mechanism to support such libraries, which I doubt exist.

Can anyone explain how such libraries are compiled and linked as templates ?

Upvotes: 0

Views: 58

Answers (1)

user0042
user0042

Reputation: 8018

Can anyone explain how such libraries are compiled and linked as templates ?

Templated code cannot be exported from a binary, but non templated (as e.g. used in base classes, helper functions, etc.) can.

Libraries like boost do not consist only of templated classes and functions as provided in the header files, but also of parts that can be distributed in binary form. The latter is what forms the .so files.

Upvotes: 3

Related Questions