Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7954 Discussions

Questions about templates ands shared libraries

Lingfeng_C_Intel
Employee
193 Views

Our customer met one issueabout templates in 10.1 and fixed in 11.0. but he still has one question about templates.
Below is the description about his issue.
----------------------------------
We had an issue where we generated a .so library from a .a library. When linking an application to the .so version, one particular template instantiation was causing an 'undefined symbol' error - even though there was no problem with the .a version of the library.

We determined that this was a problem with various 9.1, 10.0, and 10.1 compilers. However, thankfully, it appears fixed as of the recent 11.0 compilers.

The template in question was 'declared' in a header file, and its point of instantiation preceeded the actual definition and body of the template. A forward reference, if you will. (See Stroustrup chapter 13.7.) We worked around the problem by inserting an explicit instantiation of the template, and now the older compilers will compile the code too.

But in our quest for understanding, how are templates handled differently in a .so environment than in a .a environment? Does the run-time loader actually get involved and do some kind of just-in-time compilation? (I am thinking of a possible example of swapping versions of the STL by changing shared libs.) Is there some documentation that describes the technicalities of templates in the Intel documentation?
------------------

Any one who can provide some suggesetion?

Thanks,
Wise

0 Kudos
1 Reply
Om_S_Intel
Employee
193 Views
Quoting - (Intel)

Our customer met one issueabout templates in 10.1 and fixed in 11.0. but he still has one question about templates.
Below is the description about his issue.
----------------------------------
We had an issue where we generated a .so library from a .a library. When linking an application to the .so version, one particular template instantiation was causing an 'undefined symbol' error - even though there was no problem with the .a version of the library.

We determined that this was a problem with various 9.1, 10.0, and 10.1 compilers. However, thankfully, it appears fixed as of the recent 11.0 compilers.

The template in question was 'declared' in a header file, and its point of instantiation preceeded the actual definition and body of the template. A forward reference, if you will. (See Stroustrup chapter 13.7.) We worked around the problem by inserting an explicit instantiation of the template, and now the older compilers will compile the code too.

But in our quest for understanding, how are templates handled differently in a .so environment than in a .a environment? Does the run-time loader actually get involved and do some kind of just-in-time compilation? (I am thinking of a possible example of swapping versions of the STL by changing shared libs.) Is there some documentation that describes the technicalities of templates in the Intel documentation?
------------------

Any one who can provide some suggesetion?

Thanks,
Wise


The compiler translates the source acoording to C++ rule. The translation process is same for .so and .a. There is no just in time compilation by the loader. In fact loader is not involved in translation. Youcould read a c++ textbook.
0 Kudos
Reply