Boost logo

Boost :

Subject: Re: [boost] version conflicts: is there a solution?
From: Bjørn Roald (bjorn_at_[hidden])
Date: 2009-06-28 09:31:05


On Sunday 28 June 2009 11:21:08 am Bjørn Roald wrote:
> On Saturday 27 June 2009 10:17:06 pm Ilya Bobir wrote:
> > As this is not a ODR, you can probably work around it by just removing
> > all symbols that refer to boost from your library. strip can be used to
> > perform such a task. It seems to accept wildcards, so you may be able
> > to remove all symbols in boost namespace with just one invocation. You
> > only need to figure out the correct wild card as the C++ symbols will be
> > mangled by the compiler in a compiler dependent way.
>
> Nice. I have never thought of strip as a tool for other things than
> removing debug info. This can actually be a useful suggestion.

Sadly it does not work. I just did some testing and on Linux and it seems
this will not work, not even for header only boost libs. Ultimately I end up
with linking errors ("undefined symbols") or in the case of header only libs
strip refuses to cooperate with warnings like this:

strip: not stripping symbol `_ZN5boost1A3fooEv' because it is named in a
relocation

I do not know what is meant by relocation here, but if I interprets this
correctly the strip tool does not attempts to remove the symbol purely as a
reference to the code. It attempts to remove the code pointed to by the
symbol as well. Hence, it refuses to remove symbols that are in use by other
code in same translation unit.

If anybody is interested, below is listings of what I tested.

-- Bjørn

bjorn_at_frodo2:~/src/c++/test$ cat a.hpp
namespace boost
{
  class A
  {
    public:
      const char* foo();
  };
}

bjorn_at_frodo2:~/src/c++/test$ cat a.cpp
#include "a.hpp"

namespace
{
  const char astring[] = "aaaaa";

}

const char* boost::A::foo()
{
  return "aaaappp";//astring;
}

bjorn_at_frodo2:~/src/c++/test$ cat b.hpp

namespace mylib
{
  int lib_func();
}

bjorn_at_frodo2:~/src/c++/test$ cat b.cpp
#include "b.hpp"
//#include "a.hpp"
#include "a.cpp"
#include <iostream>

namespace mylib
{
  int lib_func()
  {
    boost::A a;
    std::cout << a.foo() << std::endl;
    return 0;
  }
}

bjorn_at_frodo2:~/src/c++/test$ cat c.cpp
#include "b.hpp"

int main()
{
  return mylib::lib_func();
}

bjorn_at_frodo2:~/src/c++/test$ c++ -c b.cpp

bjorn_at_frodo2:~/src/c++/test$ ar r libmy.a b.o

bjorn_at_frodo2:~/src/c++/test$ c++ c.cpp libmy.a

bjorn_at_frodo2:~/src/c++/test$ ./a.out
aaaappp

bjorn_at_frodo2:~/src/c++/test$ nm -C libmy.a

b.o:
000000000000007e t global constructors keyed to _ZN5boost1A3fooEv
0000000000000041 t __static_initialization_and_destruction_0(int, int)
0000000000000000 T boost::A::foo()
000000000000000f T mylib::lib_func()
                 U std::ostream::operator<<(std::ostream& (*)(std::ostream&))
                 U std::ios_base::Init::Init()
                 U std::ios_base::Init::~Init()
                 U std::cout
                 U std::basic_ostream<char, std::char_traits<char> >&
std::endl<char, std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&)
0000000000000000 b std::__ioinit
                 U std::basic_ostream<char, std::char_traits<char> >&
std::operator<< <std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)
                 U __cxa_atexit
                 U __dso_handle
                 U __gxx_personality_v0

bjorn_at_frodo2:~/src/c++/test$ strip -w -N *boost* libmy.a

strip: not stripping symbol `_ZN5boost1A3fooEv' because it is named in a
relocation

or streaming mangled output through c++filt

bjorn_at_frodo2:~/src/c++/test$ strip -w -N *boost* libmy.a 2>&1 | c++filt
strip: not stripping symbol `boost::A::foo()' because it is named in a
relocation

-- 
Bjørn
 
 ,   

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk