UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C++
  • » undefined symbol: in using shared library by dlopen command

#1 2016-09-27 09:59 AM

PANKAJ_DEV
Member
Registered: 2016-09-27
Posts: 2

undefined symbol: in using shared library by dlopen command

Hi All,
I am having main program which has one base class that needs to be used by shared library.
Base class has some pure virtual method that derived class in shared library needs to be over written.

Main program load shared library using dlopen system call.
dlopen("shared file name", RTLD_NOW|RTLD_GLOBAL);

Base class
class RateComputer
{
  public:
    RateComputer();
    virtual ~RateComputer();

    virtual void OnMarketData() = 0;
    virtual void OnConfigFileUpdate() = 0;

  private:

  };

Derived class in shared library.
  class WeightedRateComputer : public RateComputer
  {
  public:

    WeightedRateComputer();
    ~WeightedRateComputer();

    void OnMarketData();
    void OnConfigFileUpdate();

  private:

};

While compilation of binary and so file I have added -rdynamic flag. But during loading of library it gives error "undefined symbol: _ZTI12RateComputer".

When i run nm command as  "nm binary-name | grep RateComputer" I have got below output

00000000004435a0 t _ZNKSt10_HashtableIsSt4pairIKsSt6vectorIP12RateComputerSaIS4_EEESaIS7_ENSt8__detail10_Select1stESt8equal_toIsESt4hashIsENS9_18_Mod_range_hashingENS9_20_Default_ranged_hashENS       9_20_Prime_rehash_policyENS9_17_Hashtable_traitsILb0ELb0ELb1EEEE19_M_find_before_nodeEmRS1_m.isra.159
0000000000443f40 W _ZNSt10_HashtableISsSt4pairIKSsP12RateComputerESaIS4_ENSt8__detail10_Select1stESt8equal_toISsESt4hashISsENS6_18_Mod_range_hashingENS6_20_Default_ranged_hashENS6_20_Prime_reha       sh_policyENS6_17_Hashtable_traitsILb1ELb0ELb1EEEE10_M_emplaceIIS0_ISsS3_EEEES0_INS6_14_Node_iteratorIS4_Lb0ELb1EEEbESt17integral_constantIbLb1EEDpOT_
0000000000443f40 W _ZNSt10_HashtableISsSt4pairIKSsP12RateComputerESaIS4_ENSt8__detail10_Select1stESt8equal_toISsESt4hashISsENS6_18_Mod_range_hashingENS6_20_Default_ranged_hashENS6_20_Prime_reha       sh_policyENS6_17_Hashtable_traitsILb1ELb0ELb1EEEE10_M_emplaceIJS0_ISsS3_EEEES0_INS6_14_Node_iteratorIS4_Lb0ELb1EEEbESt17integral_constantIbLb1EEDpOT_
0000000000443d30 W _ZNSt10_HashtableISsSt4pairIKSsP12RateComputerESaIS4_ENSt8__detail10_Select1stESt8equal_toISsESt4hashISsENS6_18_Mod_range_hashingENS6_20_Default_ranged_hashENS6_20_Prime_reha       sh_policyENS6_17_Hashtable_traitsILb1ELb0ELb1EEEE21_M_insert_unique_nodeEmmPNS6_10_Hash_nodeIS4_Lb1EEE
00000000004442c0 W _ZNSt10_HashtableIsSt4pairIKsSt6vectorIP12RateComputerSaIS4_EEESaIS7_ENSt8__detail10_Select1stESt8equal_toIsESt4hashIsENS9_18_Mod_range_hashingENS9_20_Default_ranged_hashENS9       _20_Prime_rehash_policyENS9_17_Hashtable_traitsILb0ELb0ELb1EEEE10_M_emplaceIIS0_IsS6_EEEES0_INS9_14_Node_iteratorIS7_Lb0ELb0EEEbESt17integral_constantIbLb1EEDpOT_
00000000004442c0 W _ZNSt10_HashtableIsSt4pairIKsSt6vectorIP12RateComputerSaIS4_EEESaIS7_ENSt8__detail10_Select1stESt8equal_toIsESt4hashIsENS9_18_Mod_range_hashingENS9_20_Default_ranged_hashENS9       _20_Prime_rehash_policyENS9_17_Hashtable_traitsILb0ELb0ELb1EEEE10_M_emplaceIJS0_IsS6_EEEES0_INS9_14_Node_iteratorIS7_Lb0ELb0EEEbESt17integral_constantIbLb1EEDpOT_
00000000004440d0 W _ZNSt10_HashtableIsSt4pairIKsSt6vectorIP12RateComputerSaIS4_EEESaIS7_ENSt8__detail10_Select1stESt8equal_toIsESt4hashIsENS9_18_Mod_range_hashingENS9_20_Default_ranged_hashENS9       _20_Prime_rehash_policyENS9_17_Hashtable_traitsILb0ELb0ELb1EEEE21_M_insert_unique_nodeEmmPNS9_10_Hash_nodeIS7_Lb0EEE
0000000000438ce0 W _ZNSt10_HashtableIsSt4pairIKsSt6vectorIP12RateComputerSaIS4_EEESaIS7_ENSt8__detail10_Select1stESt8equal_toIsESt4hashIsENS9_18_Mod_range_hashingENS9_20_Default_ranged_hashENS9       _20_Prime_rehash_policyENS9_17_Hashtable_traitsILb0ELb0ELb1EEEE5clearEv
0000000000443c30 W _ZNSt6vectorIP12RateComputerSaIS1_EE19_M_emplace_back_auxIIRKS1_EEEvDpOT_
0000000000443c30 W _ZNSt6vectorIP12RateComputerSaIS1_EE19_M_emplace_back_auxIJRKS1_EEEvDpOT_


But if i grep symbol which so file is searching for "_ZTI12RateComputer" I didnt get any thing.

nm rate_engine | grep _ZTI12RateComputer

does i am missing any steps?
Thank you in advance for your help.

Offline

#2 2016-09-27 12:33 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,826
Website

Re: undefined symbol: in using shared library by dlopen command

Ugh, C++ name mangling!

I'm not sure if this is your problem, but are you compiling the main program with all symbols exported?  Based on your description, that sounds like it will be necessary...  With GCC, I believe you want "-Wl,-E" to do it...

Offline

#3 2016-09-27 01:31 PM

PANKAJ_DEV
Member
Registered: 2016-09-27
Posts: 2

Re: undefined symbol: in using shared library by dlopen command

Hi RobSeace,
Thank you for reply,
I only want to export whole RateComputer class from executable. I have even used -Wl,-E but still RateComputer class functions are not exported.
But then i have removed virtual keyword from all functions of RateComputer class. Created object RateComputer in executable binary. Then i was able to see function of RateComputer in nm command. Also i can able load shared library.
I dont really understand why it is able to load symbols when object is created.

000000000043b330 T _ZN10RateEngine12ConfigReader22LoadRateComputerConfigER11CXMLDomNode
00000000004462f0 T _ZN10RateEngine19RateEngineRulesHost15GetRateComputerEv
00000000004438b0 T _ZN10RateEngine19SubscriptionManager25AddSourceSubscriptionInfoEsP12RateComputer
0000000000438650 T _ZN12RateComputerC1Ev
0000000000438650 T _ZN12RateComputerC2Ev
0000000000438660 T _ZN12RateComputerD1Ev
0000000000438660 T _ZN12RateComputerD2Ev
00000000004436b0 t ..........

Offline

#4 2016-09-27 06:47 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,826
Website

Re: undefined symbol: in using shared library by dlopen command

I'm not really up on my C++; I'm used to pure C...  But, I'm guessing it's just the way it is with virtual functions...

Another thing you can try is RTLD_LAZY instead of RTLD_NOW...  I don't know if that will help, but it might put off the need to resolve some symbols until they're actually needed, if ever...

Offline

#5 2016-10-02 11:16 AM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,230

Re: undefined symbol: in using shared library by dlopen command

I think the "RateComputer" it can't find is the constructor, which isn't virtual, but also defined nowhere.

Offline

  • Index
  • » C++
  • » undefined symbol: in using shared library by dlopen command

Board footer

Powered by FluxBB