PREV UP next StackThreads/MP: version 0.77 User's Guide

10.7: Interaction with pragma interface

The problem occurs when you are using a C++ header file that uses #pragma interface. When multiple C++ sources include such a header file and they are linked together, you observe a lot of erros saying symbols are duplicated. Symbols are names of member functions defined in the header file. This is probably a gcc bug (that exists at least in ver 2.7.2.1 on Solaris. I don't know situations in other platforms and on other versions of gcc), but I describe it here because the problem occurs faily often (most importantly when you use iostream.h that comes with g++).

stgcc command gives -fno-default-inline to gcc. When gcc compiles a C++ source that includes a header file that uses #pragma interface, it generates all the symbols defined in the header as global symbols, rather than file-scope or weak symbols. If multiple sources include such headers, they result in a link error. This is purely a gcc bug, I believe.

The problem does not occur without -fno-default-inline, in which case definitions of these symbols are not generated. The problem does not occurs without #pragma interface either, in which case symbols are defined as weak symbols. The manual of gcc says the specification about this pragma is in transition.

It would be nice if you would not encounter this problem unless you use this pragma. Unfortunately, however, library header files that come with gcc extensively use them! Most importantly, iostream.h uses it. A possible work around is to give --default_inline_is_ok to stgcc, which instructs stgcc not to pass -fno-default-inline. But then, you must make sure that gcc never inlines member function calls that appear in ST_THREAD_CREATE. You can achieve this by, for example, never calling member functions by ST_THREAD_CREATE. see Possible Slowdown by Disabling Inline for more details about --default_inline_is_ok.