Hello,

usually the compiler generates no symbol in the symbol table for an inlined
member.

inline int DerivedClass::function()
{
return 0;
}


But this is not the case in the following sample.
(See below).
where a public (external) symbol is generated.

A problem occurs when the above inline function is included in 2 independent
.cpp files and both .obj files are linked together (e.q. into a dll).

======== ExportTst1.cpp =======
class BaseClass
{
public:
virtual int function()
{
return 123;
}

};

class DerivedClass
: public BaseClass
{
public:
virtual inline int function();
};


template <class Base>
class TemplClass
: public DerivedClass
{
public:
int callFunction();

static inline Base & BaseOf(TemplClass<Base> const &);
static Base * b;
};

template <class Base>
Base * TemplClass<Base>::b = 0;


template <class Base>
int TemplClass<Base>::callFunction()
{
return BaseOf(*this).Base::function();
}


template <class Base>
inline Base & TemplClass<Base>::BaseOf(TemplClass<Base> const &)
{
return *b;
}


inline int DerivedClass::function()
{
return 0;
}

template TemplClass<DerivedClass>;
===============================

to compile:
cl -W4 -nologo -D__WINDOWS__ /LD -c ExportTst1.cpp

dumpbin /SYMBOLS ExportTst1.obj

in a VC++ 8.0 Session.

Note : The Problem flushes when the last statement
template TemplClass<DerivedClass>;
is removed. But i need the explizit template instantation. The original code
is splitted into multiple files (the inline function are in a .inl file,
the template functions are in a .c file, the classes/templates in a .hpp and
the templ. instance is a client.cpp file).

any ideas?



--
mit freundlichen Grüßen/best regards
mario semo

Re: unexpected public symbol in .obj for inlined function by Ulrich

Ulrich
Tue Oct 23 07:38:47 PDT 2007

Mario Semo wrote:
> usually the compiler generates no symbol in the symbol table for an
> inlined member.

Not so, see the thread "inline functions are reported as weak symbols in .o
file ( by nm - marked as W )" in comp.lang.c++.moderated.


> inline int DerivedClass::function()
> {
> return 0;
> }
>
>
> But this is not the case in the following sample.
> (See below).
> where a public (external) symbol is generated.
>
> A problem occurs when the above inline function is included in 2
> independent .cpp files and both .obj files are linked together (e.q. into
> a dll).
>
> ======== ExportTst1.cpp =======
> class BaseClass
> {
> public:
> virtual int function()
> {
> return 123;
> }
>
> };
>
> class DerivedClass
> : public BaseClass
> {
> public:
> virtual inline int function();
> };
>
>
> template <class Base>
> class TemplClass
> : public DerivedClass
> {
> public:
> int callFunction();
>
> static inline Base & BaseOf(TemplClass<Base> const &);
> static Base * b;
> };
>
> template <class Base>
> Base * TemplClass<Base>::b = 0;
>
>
> template <class Base>
> int TemplClass<Base>::callFunction()
> {
> return BaseOf(*this).Base::function();
> }
>
>
> template <class Base>
> inline Base & TemplClass<Base>::BaseOf(TemplClass<Base> const &)
> {
> return *b;
> }
>
>
> inline int DerivedClass::function()
> {
> return 0;
> }
>
> template TemplClass<DerivedClass>;

I'm not 100% sure if that is what is biting you here, but I found that if I
derive from a template and export that class from a DLL, it also exports
the (otherwise inline) members of the baseclass. I personally consider that
a bug, but in a discussion there were also some other opinions.

However, here you only have the same inline function compiled twice in the
same executable ... I wonder, what exactly is the errormessage?

> Note : The Problem flushes when the last statement
> template TemplClass<DerivedClass>;
> is removed. But i need the explizit template instantation. The original
> code is splitted into multiple files (the inline function are in a .inl
> file, the template functions are in a .c file, the classes/templates in a
> .hpp and the templ. instance is a client.cpp file).

Hmmm, what is the difference between the content of the .inl file and the .c
file? Also, just to make sure, MSVC treats all .c files as C code and not
C++!

Uli


Re: unexpected public symbol in .obj for inlined function by Ben

Ben
Wed Oct 24 08:25:52 PDT 2007


"Ulrich Eckhardt" <eckhardt@satorlaser.com> wrote in message
news:ukd1v4-pu3.ln1@satorlaser.homedns.org...
> Mario Semo wrote:
>> usually the compiler generates no symbol in the symbol table for an
>> inlined member.
>
> Not so, see the thread "inline functions are reported as weak symbols in
> .o
> file ( by nm - marked as W )" in comp.lang.c++.moderated.

I think the Microsoft compiler hasn't any support for "weak symbols". Just
from the title of the other post it is evident that they are discussing a
*nix platform and toolchain.