Comeau C++ Export Overview

Copyright © 1992-2013 Comeau Computing, EDG

Exported Templates

Comeau C++ introduced its implementation of export in a beta release during mid-2002. A general released was provided in early 2003. This completes Comeau's support of all core language features. Comeau C++ now supports the core language of C++03 (C++98 plus TC1).

Some more overview information on export can be found by clicking here.

Exported templates are templates declared with the keyword export. 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 special because its definition does not need to be present in a translation unit that uses that template. In other words, the definition of an exported (non-class) template does not need to be explicitly or implicitly included in a translation unit that instantiates that template. For example, the following is a valid C++ program consisting of two separate translation units:

// File 1:
#include <stdio.h>

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

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

int main() {
  return min(2, 3);

// File 2:
#include <stdio.h>

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

//The definition
export template <class T> T const& min(T const &a, T const &b) {
  return a<b ? a : b;

Template Instantiation with Export

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).

Support for exported templates can be enabled using the --export command-line option. Export is enabled by default in strict ANSI mode; that is -A or --strict. With Comeau C++ for MS-Windows you'd use --A. For example, the program above could be built as follows with Comeau C++:

como --export -c file_1.c
como --export -c file_2.c
como file_1.o file_2.o

Of course, other combinations will work too, such as:

como -A file_1.c file_2.c # Use --A under MS-Windows

Finding the exported template definition

The automatic instantiation of exported templates is somewhat similar (from a user's perspective) to that of regular (included) templates. However, an instantiation of an exported template involves at least two translation units: one which requires the instantiation, and one which contains the template definition.

When a file containing definitions of exported templates is compiled, a file with a ". et" suffix is created and some extra information is included in the associated ". ti" file. The ". et" files are used later by the Comeau C++ to find the translation unit that defines a given exported template.

When a file that potentially makes use of exported templates is compiled, Comeau C++ must be told where to look for ". et" files for exported templates used by a given translation unit. By default, the compiler looks in the current directory. Optionally, other dir