tags:

views:

352

answers:

1

For the XLC compiler, templated code goes in a *.c file. Then when your program is compiled that uses the template functions, the compiler finds the template definisions in the .c file and instantiates them.

The problem is that these .c files are not by default included when doing an xlC -qmakedepend to generate the build dependencies. So if you change one of those .c files, you won't automatically build everything that depends on it.

Has anyone found a good solution to this problem?

+1  A: 

In short, the answer is to migrate off using the XLC's tempinc utility.

The tempinc utility requires you to set up your files with the template declarations in your header (.h or .hpp) file and your implementations in a .c file (this extension is mandatory). As the compiler finds template instantiations, it will put explicit instantiations in a another source file in your tempinc directory, forcing code to be generated for them. The compiler knows to find the template definitions declered in foo.h in foo.c.

The problem I specified is that the dependency builders don't know about this, and thus can't include your .c files in the dependencies.

With Version 6.0 IBM recommends using a the -qtemplateregistry setting rather than -qtempinc. Then, you can use a typical template set up of including the template definitions in your header file, which will then be visible to the dependency finder, or putting them in a separate file which you #include from your header file, and will also be found using the dependency finder.

If you are migrating from using -qtempinc, you can conditionally #include your template implementation file from your declaration file with code like below:

// end of foo.h
#ifndef __TEMPINC__          
#include "foo.c"       
#endif

Thus your code will build and link if you ever decide to go back to using the -qtempic setting.

JohnMcG