Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Qt Creator clang weak-vtable warnings and __declspec(dllexport)
Forum Updated to NodeBB v4.3 + New Features

Qt Creator clang weak-vtable warnings and __declspec(dllexport)

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
3 Posts 3 Posters 4.1k Views 3 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
    thosrtanner
    wrote on last edited by A Former User
    #1

    I keep getting a weak-vtable warning (<classname> has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit) on any of my classes which are declared like this

    class __declspec(dllexport) Example : public QDialog
    {
      Q_OBJECT
      
    public:
    
      virtual ~Example();
    

    but the class has an out-of-line export method.

    If I change the dllexport to dllimport the message goes away.

    A note: The actual declspec is embedded in a macro, so that the header can be used by clients or the implementation, but I don't particularly want to do something like #ifdef __clang in case this project ends up getting compiled with clang in the future.

    So how do I et it not to produce the warning in this case? is it a problem with the version of clang Qt uses?

    kshegunovK 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Here you have an explanation on how to use Qt's provided macros to handle export/import of symbols.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • T thosrtanner

        I keep getting a weak-vtable warning (<classname> has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit) on any of my classes which are declared like this

        class __declspec(dllexport) Example : public QDialog
        {
          Q_OBJECT
          
        public:
        
          virtual ~Example();
        

        but the class has an out-of-line export method.

        If I change the dllexport to dllimport the message goes away.

        A note: The actual declspec is embedded in a macro, so that the header can be used by clients or the implementation, but I don't particularly want to do something like #ifdef __clang in case this project ends up getting compiled with clang in the future.

        So how do I et it not to produce the warning in this case? is it a problem with the version of clang Qt uses?

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #3

        @thosrtanner
        Hi,
        As an addition to @SGaist's link, also make sure Example::~Example() is defined. While the standard requires all virtual methods declarations be defined some compilers and linkers will ignore that and will not generate vtable entries for undefined methods, thus builds will silently succeed.

        Kind regards.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        0
        • JonBJ JonB referenced this topic on

        • Login

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