Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

shared object symbol visibility

chilabot
Occasional Advisor

shared object symbol visibility

I'm trying to compile a C++ shared object, and the weirdest thing happens. Whenever some code is in there, all the symbols from a certain compilation object dissappear. When I remove that code, they appear. For instance:

 

#include <boost/ptr_container/ptr_vector.hpp>

namespace nsp
{

    template <typename Type>
    struct Holder
    {
        boost::ptr_vector<Type> vec;
    };

    class Object { int a; };

    Holder<Object> holder;

    void testIt()
    {
        // holder.vec.push_back(new Object());
    }
}

 

$g++ -shared test.cpp -o test.so -I${BOOST_INCLUDE_GCC}/1.51

 

$ nm test.so | grep testIt | c++filt
[258] | 67118528| 32|FUNC |GLOB |0| .text|nsp::testIt()

 

But if I uncomment the line inside 'testIt', the 'nm' command shows nothing. If there's no 'Holder' template, just the 'vec', the symbols appears. If the type is just an 'int', the symbol appears.

 

What could be the cause of this?

 

$ g++ --version
g++ (GCC) 4.7.0
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 

$ uname -a
HP-UX rx8km B.11.31 U ia64 2229485251 unlimited-user license

 

 

5 REPLIES
Dennis Handly
Acclaimed Contributor

Re: shared lib symbol visibility (hidden local symbol)

It would be helpful to run nm(1) on the object file instead of a shlib.

 

>If the type is just an 'int', the symbol appears.

 

The template type as in: ?

Holder<int> holder;

Or:

boost::ptr_vector<int> vec;

chilabot
Occasional Advisor

Re: shared lib symbol visibility

>It would be helpful to run nm(1) on an object file instead of a shlib.

 

What should be run on a shlib?

 

>>If the type is just an 'int', the symbol appears.

>The template type as in: ?

>Holder<int> holder;

>Or:

>boost::ptr_vector<int> vec;

 

Holder<int> holder;

 

Dennis Handly
Acclaimed Contributor

Re: shared lib symbol visibility (hidden local symbol)

>What should be run on a shlib?

 

You already did this.  Now run nm(1) on the object file.

chilabot
Occasional Advisor

Re: shared lib symbol visibility (missing symbol)

I did that and the symbol appears. I tried using the shared object anyways and it worked even thou the nm does not show the symbol. Weird.

Highlighted
Dennis Handly
Acclaimed Contributor

Re: shared lib symbol visibility (hidden local symbol)

>I did that and the symbol appears.

 

Can you provide the nm(1) output, perhaps the symbol is only local and so doesn't get put in the shlib symbol table?