Boost logo

Boost Users :

Subject: Re: [Boost-users] [Exception] Duplicate symbol error when using errinfo_api_function in static library
From: Georg Leidinger (georg.leidinger_at_[hidden])
Date: 2013-10-02 18:06:49

Hi Emil,

I was able to figure out some more information about the issue and I could
isolate it a little bit more. First it doesn't matter if it is a static or
a shared library. Second it is not directly related to the
*Boost.Exception*library but to the template class
*error_info* which is used to create the predefined errinfo_xyz types. It
is enough to instantiate the *errinfo_api_function* type in both
doSomething() methods in the both implementation files. I am not so good in
templates but I guess that the compiler creates the same symbol in both
object files (ClassA.o and ClassB.o) for the type *errinfo_api_function.* I
can see this via nm that I have the following line in both object files:

*0000000000059860 s __ZTIN5boost21errinfo_api_function_E*
*0000000000059870 s __ZTIN5boost21errinfo_api_function_E *
Now, when the linker tries to link ClassA.o and ClassB.o to the main.o the
both symbols clashes. But that would mean I could never use *Boost.Exception
* or any other template instantiated type in a library.

Best Regards

2013/10/2 Emil Dotchevski <emildotchevski_at_[hidden]>

> On Tue, Oct 1, 2013 at 2:16 AM, Georg Leidinger <
> georg.leidinger_at_[hidden]> wrote:
>> Dear readers,
>> I encountered a problem in my project when using *Boost.Exception* with
>> the predefined types errinfo_xyz in a library project. I have two classes
>> ClassA and ClassB in my library which both throw a boost::exception with
>> errinfo_api_function type in their implementation file (.cpp) These both
>> classes are compiled into a static library with the C/C++-Flags
>> -fvisibility=hidden.
>> Then I have a main.cpp which creates an instance of ClassA and ClassB and
>> links to the library which contains ClassA.o and ClassB.o. When I compile
>> the main.cpp I get the linker error duplicate symbol for the
>> errinfo_api_function object in ClassA.o and ClassB.o. If I remove the
>> visibility=hidden flag, it links without problems. I am not an expert on
>> the compiler flags, but I saw that many libraries use the visibility=hidden
>> flag so I think it would be good, if my lib could also use it.
> Honestly I have no idea why this would happen. Anyone?
> --
> Emil Dotchevski
> Reverge Studios, Inc.
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at