Exported Templates

The Intel® C++ Compiler supports exported templates using the following options:

Option Description
-export Enable recognition of exported templates. Supported in C++ mode only.
-export_dir dir Specifies a directory name to be placed on the exported template search path. The directories are used to find the definitions of exported templates and are searched in the order in which they are specified on the command-line. The current directory is always the first entry on the search path.

Exported templates are templates declared with the export keyword. Exporting a class template is equivalent to exporting each of its static data members and each of its non-inline member functions. An exported template is unique because its definition does not need to be present in a translation unit that uses that template. For example, the following C++ program consists of two separate translation units:

// file1.cpp

#include <stdio.h>

static void trace() { printf("File 1\n"); }

export template<class T> T const& min(T const&, T const&);

int main() {


  return min(2, 3);



// file2.cpp

#include <stdio.h>

static void trace() { printf("File 2\n"); }

export template<class T> T const& min(T const &a, T const &b) {


  return a<b? a: b;


Note that these two files are separate translation units: one is not included in the other. That allows the two functions trace() to coexist (with internal linkage).


prompt>icpc -export -export_dir /usr2/export/ -c file1.cpp

prompt>icpc -export -export_dir /usr2/export/ -c file2.cpp

prompt>icpc -export -export_dir /usr2/export/ file1.o file2.o