[C++-sig] [boost.python] Can't import a wrapped template class

Stefan Seefeld stefan at seefeld.name
Fri Oct 26 20:28:11 CEST 2012


On 10/26/2012 02:16 PM, Paul O. Seidon wrote:
> Stefan Seefeld wrote:
>
>> On 10/26/2012 01:50 PM, Paul O. Seidon wrote:
>>> The ctor is decl'ed in varbls.h as
>>>
>>> _Variable();
>>>
>>> and it's def'ed in varbls.cpp like so:
>>>
>>> template <typename TYPE>
>>> _Variable<TYPE>::_Variable()
>>> : _value( 0)
>>> {
>>>      //ctor
>>> }
>> That doesn't work. When the compiler compiles varbls.cpp, it doesn't
>> know what types to instantiate the _Variable template for, so you need
>> to either explicitly instantiate it for all the types you use in your
>> module, or keep the definitions in the varbls.h header so the compiler
>> can implicitly instantiate them when compiling the Python module.
>>
>>     Stefan
>>
> That didn't make any difference. And it would have surprised me, if it did: 
> varbls.h contains the declaration, varbls.cpp contains the definition, the 
> wrapper is in main.cpp. So if the compiler sees any need to include 
> sometihng, it will and the linker will link the definition.

Sorry, let's back up a little. What are you referring to as "the
definition" in the above ?

Where is the "_Variable<double>::_Variable()" constructor defined ? You
didn't show me where it was. You only showed me the (still parametrized)
definition in varbls.cpp. If the compiler sees the parametrized
constructor definition, it doesn't know what types to instantiate it
for, so it does nothing (other than validate the code to some degree).
It's only when it instantiates the template for a particular type that
it generates the missing symbol.
But - according to the small chunks of code you have shown me - it only
attempts that instantiation implicitly in your module's code. But at
that point it doesn't see the constructor definition, so it can't
instantiate that.

Perhaps showing a little more of your code / setup would help.

    Stefan

-- 

      ...ich hab' noch einen Koffer in Berlin...



More information about the Cplusplus-sig mailing list