Re: What might cause 'undefined symbol' for typeinfo when loading dynamic library built with C++11 enabled?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thank you Jonathan for your reply.

The class does indeed contain a virtual method, but that method is defined.
So I don't think that is the problem.

I've disabled the loading of the troublesome .so library file and now
another library is refusing to load. I am wondering whether this new
problem is related and so would like to ask you about it.  The error
message now is:

undefined symbol: _ZN8StarLibs7LinkSim2NR6NRDmrs18MAX_NUM_CDM_GROUPSE (
StarLibs::LinkSim::NR::NRDmrs::MAX_NUM_CDM_GROUPS )

This symbol is a constant defined in a class's header (.h file):

namespace StarLibs {
namespace LinkSim {
namespace NR
{
class NRDmrs
{
public:

        static const unsigned DMSR_MAX_NSCID = 1;
        static const unsigned MAX_NUM_CDM_GROUPS = 3;

This takes me back to my earlier comment.  In C++14, do I need to declare
such constants in a .cpp source file in order to give them storage and so
make them load?

On Thu, Dec 13, 2018 at 11:23 AM Jonathan Wakely <jwakely.gcc@xxxxxxxxx>
wrote:

> On Thu, 13 Dec 2018 at 10:46, David Aldrich wrote:
> >
> > Our C++ application, that runs on Linux, links to dynamic libraries built
> > by us. When everything is built using gcc 7.3.0 with switch -std=c++98,
> the
> > libraries load ok. However, when I build everything without that switch
> > (i.e. with C++11)
>
> N.B. the default is -std=gnu++14 not 11.
>
> > dlopen() reports an undefined symbol:
> >
> > undefined symbol: _ZTIN8StarLibs7LinkSim2NR13StarOfdmGenNRE ( typeinfo
> for
> > StarLibs::LinkSim::NR::StarOfdmGenNR )
> >
> > (The demangled symbol name is in brackets.)
> >
> > What could cause missing typeinfo, which is apparently for the class?
>
> It could be any number of things. Maybe the C++98 version of the
> application doesn't need that typeifo, so never notices it's not
> there. Or maybe it does need it, but when built as C++11 the class
> doesn't define its typeinfo. My guess is the latter. See
> https://gcc.gnu.org/wiki/VerboseDiagnostics#missing_vtable (the same
> logic applies to the typeinfo as to the vtable).
>
> If your class looks like this then its key function will be different
> in C++98 and C++11:
>
> class Foo {
> #if __cplusplus >= 201103:
>   virtual void bar();
> #endif
>
> virtual void baz();
> };
>
> If you don't define Foo::bar() somewhere then the typeinfo will never
> get emitted.
>
>
> > The class has methods that return const. Also the class's header file
> > #includes another class's header file and that included class contains
> some
> > static const members.
>
> That's completely irrelevant to typeinfo.
>
> > I tried declaring those members in a separate .cpp
> > file to allocate them storage (that recipe fixed a similar error in
> another
> > part of the code) but it did not fix this problem.
>



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux