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. Linking error when using template class from MFC Extension DLL

Linking error when using template class from MFC Extension DLL

Scheduled Pinned Locked Moved C / C++ / MFC
c++visual-studiohelpquestion
12 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.
  • B Ben M Stokland

    Have you tried to implement a method int IsEmpty(void) { ... return n; } ??? Seems like the linker can't find the body of this function... Is it a virtual class you are inheriting from? Or is int IsEmpty(void) defined as: in IsEmtpy(void) = 0; ??:confused:

    D Offline
    D Offline
    D D de Kerf
    wrote on last edited by
    #3

    I've implemented all the functions inside the class and it all worked when it was still outside the MFC Extension DLL... There is one thing though, but I don't think it could cause this error: the implementation is done in the .h-file. I would like to try to move the implementation to the .cpp-file, but I never got that working on a template class... :(( Structured programming vs. chaotic mind boggling

    B T 2 Replies Last reply
    0
    • D D D de Kerf

      I've implemented all the functions inside the class and it all worked when it was still outside the MFC Extension DLL... There is one thing though, but I don't think it could cause this error: the implementation is done in the .h-file. I would like to try to move the implementation to the .cpp-file, but I never got that working on a template class... :(( Structured programming vs. chaotic mind boggling

      B Offline
      B Offline
      Ben M Stokland
      wrote on last edited by
      #4

      It shouldn't make any difference if the implementation is in the header or in the cpp. The linker doesn't care. It's just a matter of making readable code. Doing all your implementation in the header, just makes the code harder to maintain than necessary.:suss: The key point is that the linker can't find the implementation of that method.

      1 Reply Last reply
      0
      • D D D de Kerf

        I've implemented all the functions inside the class and it all worked when it was still outside the MFC Extension DLL... There is one thing though, but I don't think it could cause this error: the implementation is done in the .h-file. I would like to try to move the implementation to the .cpp-file, but I never got that working on a template class... :(( Structured programming vs. chaotic mind boggling

        T Offline
        T Offline
        Tomasz Sowinski
        wrote on last edited by
        #5

        the implementation is done in the .h-file. So there's no need to mark the template as exported. What happens when you remove AFX_EXT_CLASS? Tomasz Sowinski -- http://www.shooltz.com

        D 1 Reply Last reply
        0
        • T Tomasz Sowinski

          the implementation is done in the .h-file. So there's no need to mark the template as exported. What happens when you remove AFX_EXT_CLASS? Tomasz Sowinski -- http://www.shooltz.com

          D Offline
          D Offline
          D D de Kerf
          wrote on last edited by
          #6

          I tried it this way as well: template class AFX_EXT_CLASS myClass_Aggregate : public myClass_Object { public: myClass_Aggregate() { ... } ... } but it doesn't make a difference. It just keeps on saying that it can't link to the specific templated instance... For example, when I do this: myClass_Aggregate bla; it says it can't find the implementation of myClass_Aggregate::~myClass_Aggregate(void) The weird thing is that it apparantly CAN find the implementation of the CONSTRUCTOR... I've been looking around a little, but am quite pessimistic about a good outcome for this problem.... Please help me before I get depressed ;) Structured programming vs. chaotic mind boggling

          T 1 Reply Last reply
          0
          • D D D de Kerf

            I tried it this way as well: template class AFX_EXT_CLASS myClass_Aggregate : public myClass_Object { public: myClass_Aggregate() { ... } ... } but it doesn't make a difference. It just keeps on saying that it can't link to the specific templated instance... For example, when I do this: myClass_Aggregate bla; it says it can't find the implementation of myClass_Aggregate::~myClass_Aggregate(void) The weird thing is that it apparantly CAN find the implementation of the CONSTRUCTOR... I've been looking around a little, but am quite pessimistic about a good outcome for this problem.... Please help me before I get depressed ;) Structured programming vs. chaotic mind boggling

            T Offline
            T Offline
            Tomasz Sowinski
            wrote on last edited by
            #7

            The code posted in last msg still contains AFX_EXT_CLASS. Are you sure you've actually removed AFX_EXT_CLASS? Tomasz Sowinski -- http://www.shooltz.com

            D 1 Reply Last reply
            0
            • T Tomasz Sowinski

              The code posted in last msg still contains AFX_EXT_CLASS. Are you sure you've actually removed AFX_EXT_CLASS? Tomasz Sowinski -- http://www.shooltz.com

              D Offline
              D Offline
              D D de Kerf
              wrote on last edited by
              #8

              Wait, I'm a little off here, I guess.... I would like to use the template class outside the DLL (i.e. export the template class). But when I remove the AFX_EXT_CLASS from the class definition of myClass_Aggregate, the class won't be exported at all, right? So then I won't be able to use it outside the DLL, right??? Or perhaps I don't understand this very well... Structured programming vs. chaotic mind boggling

              T 1 Reply Last reply
              0
              • D D D de Kerf

                Wait, I'm a little off here, I guess.... I would like to use the template class outside the DLL (i.e. export the template class). But when I remove the AFX_EXT_CLASS from the class definition of myClass_Aggregate, the class won't be exported at all, right? So then I won't be able to use it outside the DLL, right??? Or perhaps I don't understand this very well... Structured programming vs. chaotic mind boggling

                T Offline
                T Offline
                Tomasz Sowinski
                wrote on last edited by
                #9
                1. When you post code, replace > and < with > and <. The template arguments are lost without that - I had to view the HTML source to find out that you're using AFX_EXT_CLASS in template argument declaration. This isn't necessary. 2) Template itself doesn't produce any code, so there's no need to export it. All information is in .h file, as you have already mentioned. 3) Your template derives from non-template myClass_object. This class must be exported. Tomasz Sowinski -- http://www.shooltz.com
                D 1 Reply Last reply
                0
                • T Tomasz Sowinski
                  1. When you post code, replace > and < with > and <. The template arguments are lost without that - I had to view the HTML source to find out that you're using AFX_EXT_CLASS in template argument declaration. This isn't necessary. 2) Template itself doesn't produce any code, so there's no need to export it. All information is in .h file, as you have already mentioned. 3) Your template derives from non-template myClass_object. This class must be exported. Tomasz Sowinski -- http://www.shooltz.com
                  D Offline
                  D Offline
                  D D de Kerf
                  wrote on last edited by
                  #10

                  >1) When you post code, replace > and < with > and <. The template arguments are >lost without that - I had to view the HTML source to find out that you're using >AFX_EXT_CLASS in template argument declaration. This isn't necessary. Whoops. Sorry. Never thought of that. Pretty stupid of me. >2) Template itself doesn't produce any code, so there's no need to export it. All >information is in .h file, as you have already mentioned. Right. >3) Your template derives from non-template myClass_object. This class must be exported. It was already exported, but it didn't seem to help. My theory about the whole messy situation is that template-classes can't be exported. I read somewhere else over at CodeGuru.com that the template construction is a compile-time trick and since the extension dll has already been compiled, it probably can't use any template classes. I've solved the problem by repeating the code of the template class inside the .h-file that I distribute together with the .lib en .dll file. That way it is compiled both in the extension DLL and in the application that uses the dll. Not an ideal solution, but it works for now. If anyone has valuable input about this situation, I'd love to hear it! Thanks for all your help so far. Dave Structured programming vs. chaotic mind boggling

                  T 1 Reply Last reply
                  0
                  • D D D de Kerf

                    >1) When you post code, replace > and < with > and <. The template arguments are >lost without that - I had to view the HTML source to find out that you're using >AFX_EXT_CLASS in template argument declaration. This isn't necessary. Whoops. Sorry. Never thought of that. Pretty stupid of me. >2) Template itself doesn't produce any code, so there's no need to export it. All >information is in .h file, as you have already mentioned. Right. >3) Your template derives from non-template myClass_object. This class must be exported. It was already exported, but it didn't seem to help. My theory about the whole messy situation is that template-classes can't be exported. I read somewhere else over at CodeGuru.com that the template construction is a compile-time trick and since the extension dll has already been compiled, it probably can't use any template classes. I've solved the problem by repeating the code of the template class inside the .h-file that I distribute together with the .lib en .dll file. That way it is compiled both in the extension DLL and in the application that uses the dll. Not an ideal solution, but it works for now. If anyone has valuable input about this situation, I'd love to hear it! Thanks for all your help so far. Dave Structured programming vs. chaotic mind boggling

                    T Offline
                    T Offline
                    Tomasz Sowinski
                    wrote on last edited by
                    #11

                    What exactly do you want to achieve? Do you want users of your DLL to pass types unknown inside the DLL as template arguments?

                    myClass_aggregate<classFromSomeOtherExeOrDll> x;

                    In this case, you need to distribute .h file. Template construction occurs at compile time - this is no surprise, because template itself is not a complete type. Compiler needs to know what are the template arguments. Or -- maybe you just want to export a few specializations of your template, like this:

                    myClass_aggregate<classFromThisExtenstionDll> y;
                    myClass_aggregate<anotherClassFromThisExtenstionDll> z;

                    In this scenario you have one more option - you can explicitly instantiate the type. See "Explicit Instantiation" in C++ Language Reference included in VC++ help and KB article Q168958 for more details. Tomasz Sowinski -- http://www.shooltz.com

                    D 1 Reply Last reply
                    0
                    • T Tomasz Sowinski

                      What exactly do you want to achieve? Do you want users of your DLL to pass types unknown inside the DLL as template arguments?

                      myClass_aggregate<classFromSomeOtherExeOrDll> x;

                      In this case, you need to distribute .h file. Template construction occurs at compile time - this is no surprise, because template itself is not a complete type. Compiler needs to know what are the template arguments. Or -- maybe you just want to export a few specializations of your template, like this:

                      myClass_aggregate<classFromThisExtenstionDll> y;
                      myClass_aggregate<anotherClassFromThisExtenstionDll> z;

                      In this scenario you have one more option - you can explicitly instantiate the type. See "Explicit Instantiation" in C++ Language Reference included in VC++ help and KB article Q168958 for more details. Tomasz Sowinski -- http://www.shooltz.com

                      D Offline
                      D Offline
                      D D de Kerf
                      wrote on last edited by
                      #12

                      Actually I wanted what you first described... But reflecting on it, I only want to use the aggregate for subtypes of the myClass_Object class, so that may bring me to your second case... Is it so, that when I explicitly instatiate a supertype, that it will also work for all subtypes of that supertype?? In that case I am probably able to solve it the elegant way, anyway! Thanx a lot! Structured programming vs. chaotic mind boggling

                      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