Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. importing template classes from dll

importing template classes from dll

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Themis
    wrote on last edited by
    #1

    Hi, I 'm trying to import a template class from dll A to another one, dll B, where I'm subclassing it and instantiating it. However I get the following linking error: xmlCoreBuilder error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall MAGE::Builder::Builder(void)" (__imp_??0?$Builder@VScene@MAGE@@@MAGE@@QAE@XZ) referenced in function "public: __thiscall xmlCoreBuilder::SceneBuilder::SceneBuilder(void)" (??0SceneBuilder@xmlCoreBuilder@@QAE@XZ) In the following error Builder is the base template class defined in dll A and SceneBuilder is a specialized sub-class of the former defined in dll B. I get the linking error when creating an instance of the sub-class in dll B: xmlCoreBuilder::SceneBuilder* b = new xmlCoreBuilder::SceneBuilder; I'm suspecting that I might have that problem because I export a template class, but I'm not sure. Can you think of anything? Thank you, Themis

    B C 2 Replies Last reply
    0
    • T Themis

      Hi, I 'm trying to import a template class from dll A to another one, dll B, where I'm subclassing it and instantiating it. However I get the following linking error: xmlCoreBuilder error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall MAGE::Builder::Builder(void)" (__imp_??0?$Builder@VScene@MAGE@@@MAGE@@QAE@XZ) referenced in function "public: __thiscall xmlCoreBuilder::SceneBuilder::SceneBuilder(void)" (??0SceneBuilder@xmlCoreBuilder@@QAE@XZ) In the following error Builder is the base template class defined in dll A and SceneBuilder is a specialized sub-class of the former defined in dll B. I get the linking error when creating an instance of the sub-class in dll B: xmlCoreBuilder::SceneBuilder* b = new xmlCoreBuilder::SceneBuilder; I'm suspecting that I might have that problem because I export a template class, but I'm not sure. Can you think of anything? Thank you, Themis

      B Offline
      B Offline
      Bob Stanneveld
      wrote on last edited by
      #2

      Hello, You can't export template classes. This is because code is generated at compile time and DLL's work at runtime. The only way to 'export' templates is to provide the source code. This needs to be in the header file anyway.. Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

      1 Reply Last reply
      0
      • T Themis

        Hi, I 'm trying to import a template class from dll A to another one, dll B, where I'm subclassing it and instantiating it. However I get the following linking error: xmlCoreBuilder error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall MAGE::Builder::Builder(void)" (__imp_??0?$Builder@VScene@MAGE@@@MAGE@@QAE@XZ) referenced in function "public: __thiscall xmlCoreBuilder::SceneBuilder::SceneBuilder(void)" (??0SceneBuilder@xmlCoreBuilder@@QAE@XZ) In the following error Builder is the base template class defined in dll A and SceneBuilder is a specialized sub-class of the former defined in dll B. I get the linking error when creating an instance of the sub-class in dll B: xmlCoreBuilder::SceneBuilder* b = new xmlCoreBuilder::SceneBuilder; I'm suspecting that I might have that problem because I export a template class, but I'm not sure. Can you think of anything? Thank you, Themis

        C Offline
        C Offline
        cmk
        wrote on last edited by
        #3

        DLL A: BldT.h: template<class TT> class BldT {...}; typedef BldT<long> BldLong; #include "BldT.i" BldT.i: template<class TT> BldT<TT>::BldT( void ) {...} ... BldT.cpp: // The following will export all methods from BldT<long> template instance template class __declspec(dllexport) BldT<long>; DLL B: SBld.h class ScnBld : public BldLong {...}; You will still need to access BldT.h from DLL B to compile. However, you shouldn't need to provide BldT.i and can remove the #include "BldT.i" from the BldT.h that DLL B uses. ...cmk Save the whales - collect the whole set

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups