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.

Note iconNote

Exported templates are not supported with gcc 3.3 or earlier. You need gcc 3.4 or newer to use this feature.

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() {
  trace();
  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) {
  trace();
  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).

Usage

icpc -export -export-dir /usr2/export/ -c file1.cpp icpc -export -export-dir /usr2/export/ -c file2.cpp icpc -export -export-dir /usr2/export/ file1.o file2.o

See Also


Submit feedback on this help topic

Copyright © 1996-2010, Intel Corporation. All rights reserved.