Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Virtual method in library causes unresovled external
Forum Updated to NodeBB v4.3 + New Features

Virtual method in library causes unresovled external

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 173 Views
  • 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.
  • D Offline
    D Offline
    dpe3
    wrote on last edited by dpe3
    #1

    I'm using:

    • QtCreator 10.0.2
    • Qt 6.2.9
    • cmake-based projects (since that seems to be the default)
    • Windows 10

    I have a library (let's call it "LibFoo") which is used by an application (call it "Bar").

    LibFoo has a class A with a protected method getParameter(), which has an implementation in class A. This works fine, and when I build Bar, the library LibFoo is successfully linked in - no problems.

    But if I simply indicate "virtual" for getParameter(), LibFoo still builds fine but when I build Bar, it complains of an unresolved external "protected: virtual unsigned short __cdecl A::getParameter(void) <mangled name>".

    More context: A is used as a base class for two others (B and C) within LibFoo, but is not used as the base of any classes in the application Bar.

    The thing is, A has other virtual methods. These don't seem to cause problems. It doesn't seem to matter whether those other methods have overrides in B and C.

    Furthermore if I create overrides of getParameter in B and C, then the complaint about A::getParameter goes away, but now unresolved external complaints for B::getParameter and C::getParameter show up.

    Unfortunately, I can't disclose the actual code in question. More frustrating, I've not been able to reproduce a simplified example that I can post. (My attempt at a "hello" reproduction of the same scenario fails to produce the unresolved external complaints.)

    So, I'm just putting my description of the situation out there, in the hopes that someone has run across something similar and knows what might be going on.

    Further update: I tried changing the method in question to public instead of protected. That does not make any difference.

    Christian EhrlicherC 1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      @dpe3 said in Virtual method in library causes unresovled external:

      Unfortunately, I can't disclose the actual code in question.

      Then write a simple testcase. Shouldn't be that hard from your description.

      Do you properly export the classes?

      D Offline
      D Offline
      dpe3
      wrote on last edited by
      #3

      @Christian-Ehrlicher did you miss "More frustrating, I've not been able to reproduce a simplified example that I can post. (My attempt at a "hello" reproduction of the same scenario fails to produce the unresolved external complaints.)"? :-)

      In any case, I discovered the issue: Apparently, moving a project in Qt (maybe only with cmake) is not an obvious operation. In fact, I'm still not quite sure how to do it, what parts of the build directory need to be controlled, etc. But it was rebuilding the library in the OLD build directory rather than the one under the new location of the project.

      Gah! Why isn't everything that's project-specific based on relative directories by default!?

      1 Reply Last reply
      0
      • D dpe3

        I'm using:

        • QtCreator 10.0.2
        • Qt 6.2.9
        • cmake-based projects (since that seems to be the default)
        • Windows 10

        I have a library (let's call it "LibFoo") which is used by an application (call it "Bar").

        LibFoo has a class A with a protected method getParameter(), which has an implementation in class A. This works fine, and when I build Bar, the library LibFoo is successfully linked in - no problems.

        But if I simply indicate "virtual" for getParameter(), LibFoo still builds fine but when I build Bar, it complains of an unresolved external "protected: virtual unsigned short __cdecl A::getParameter(void) <mangled name>".

        More context: A is used as a base class for two others (B and C) within LibFoo, but is not used as the base of any classes in the application Bar.

        The thing is, A has other virtual methods. These don't seem to cause problems. It doesn't seem to matter whether those other methods have overrides in B and C.

        Furthermore if I create overrides of getParameter in B and C, then the complaint about A::getParameter goes away, but now unresolved external complaints for B::getParameter and C::getParameter show up.

        Unfortunately, I can't disclose the actual code in question. More frustrating, I've not been able to reproduce a simplified example that I can post. (My attempt at a "hello" reproduction of the same scenario fails to produce the unresolved external complaints.)

        So, I'm just putting my description of the situation out there, in the hopes that someone has run across something similar and knows what might be going on.

        Further update: I tried changing the method in question to public instead of protected. That does not make any difference.

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @dpe3 said in Virtual method in library causes unresovled external:

        Unfortunately, I can't disclose the actual code in question.

        Then write a simple testcase. Shouldn't be that hard from your description.

        Do you properly export the classes?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        D 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          @dpe3 said in Virtual method in library causes unresovled external:

          Unfortunately, I can't disclose the actual code in question.

          Then write a simple testcase. Shouldn't be that hard from your description.

          Do you properly export the classes?

          D Offline
          D Offline
          dpe3
          wrote on last edited by
          #3

          @Christian-Ehrlicher did you miss "More frustrating, I've not been able to reproduce a simplified example that I can post. (My attempt at a "hello" reproduction of the same scenario fails to produce the unresolved external complaints.)"? :-)

          In any case, I discovered the issue: Apparently, moving a project in Qt (maybe only with cmake) is not an obvious operation. In fact, I'm still not quite sure how to do it, what parts of the build directory need to be controlled, etc. But it was rebuilding the library in the OLD build directory rather than the one under the new location of the project.

          Gah! Why isn't everything that's project-specific based on relative directories by default!?

          1 Reply Last reply
          0
          • D dpe3 has marked this topic as solved on

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved