Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5957363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:23:25+00:00 2026-05-22T18:23:25+00:00

I have a class defined in one h file and implemented in a cpp

  • 0

I have a class defined in one h file and implemented in a cpp that is part of one lib (we’ll call it libdef).

I have two other libs that have cpp files that include this h file. One of them does dynamic_cast() to this class (we’ll call it libdyn) and the other does new for this class (we’ll call it libnew).

It seems that in one of these libs there’s typeinfo for the type but not in the other:

user@machine> ld --cref libdef.so | grep -E "typeinfo for MyClass"
ld: warning: cannot find entry symbol _start; not setting start address
typeinfo for MyClass libdef.so

user@machine> ld --cref libnew.so | grep -E "typeinfo for MyClass"
ld: warning: cannot find entry symbol _start; not setting start address
typeinfo for MyClass libdef.so

user@machine> ld --cref libdyn.so | grep -E "typeinfo for MyClass"
ld: warning: cannot find entry symbol _start; not setting start address
typeinfo for MyClass libdyn.so

As you can see both libdef and libnew use the typeinfo from libdef, but libdyn uses its own typeinfo. Why is that? How does the compiler/linker decide whether to put the typeinfo in one lib or reference it from the other?

I should note that both libnew and libdyn are built with -llibdef.

user@machine> icpc -V
Intel(R) C++ Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 12.0.0.084 Build 20101006
Copyright (C) 1985-2010 Intel Corporation.  All rights reserved.

user@machine> ld -V
GNU ld version 2.17.50.0.6-14.el5 20061020
Supported emulations:
 elf_x86_64
 elf_i386
 i386linux

After some checks I did, it depends on whether the cpp files of the lib “see” a virtual method definition or not.

This code will not result in the typeinfo symbol being in the library:

class SomeClass { public: SomeClass(); virtual void func(); };

This code will produce a typeinfo symbol in the library:

class SomeClass { public: SomeClass() {} virtual void func() {} };

When present, the typeinfo symbol will have vague linkage.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:23:26+00:00Added an answer on May 22, 2026 at 6:23 pm

    G++ probably defines the typeinfo for the class as a weak
    symbol, in every object file that needs it. One of the object
    files in libdef needs it, because it’s part of the vtable
    installed by the constructor. And one of the object files in
    libdyn needs it, because of the dynamic_cast. If all
    libnew does is a new, however, it likely wouldn’t need it
    (unless the constructor is inline). At any rate, if it really
    is a weak symbol, only one of the definitions will be
    incorporated into the final so or executable; which one is
    unspecified (but I suspect that it is the first one the linker
    encounters—which corresponds to what you’re seeing).

    None of which matters most of the time. (The exception is if
    you’re calling dlopen with RTLD_LOCAL; do this, and
    dynamic_cast is likely to fail if it executed in an .so
    other than the one with the object’s constructor.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have the core of a class defined in one file as public
I have a templated class defined (in part) as template <class T> MyClass {
I have a class with two methods defined in it. public class Routines {
I have the following members defined in a class that I'm trying to deserialise:
Let's say we have defined a CSS class that is being applied to various
I have a few tables that I've defined like the below examples: class TableA
Here's my problem: I have a virtual method defined in a .h file that
I have one class, called A, and it has it's own header file. Then
I have two different Search activities implemented with SearchManager in my app. One is
Suppose I have an array of a objects of user defined class. Wanted to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.