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. error LNK2001: unresolved external symbol "public: static struct QMetaObject .. from lib template
Forum Updated to NodeBB v4.3 + New Features

error LNK2001: unresolved external symbol "public: static struct QMetaObject .. from lib template

Scheduled Pinned Locked Moved Solved General and Desktop
28 Posts 5 Posters 11.0k Views 2 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.
  • O OPit

    Hi,
    I would like to create a custom class from the great lib QtAV, in a Qt lib template.
    When I compile my class directly from my app, it works well.
    But if I create my custom class in a custom qt lib ( (myStream.lib), I have the error : error LNK2001: unresolved external symbol "public: static struct QMetaObject... when I call it during compilation of my app :

    my custom class is InputStreamPreview :

    #include <QtAVWidgets/VideoPreviewWidget.h>
    
    class InputStreamPreview : public QtAV::VideoPreviewWidget
    {
    Q_OBJECT
    ...
    

    the complete error messages is :

    myStream.lib(moc_inputstreampreview.obj) : error LNK2001: unresolved symbol "public: static struct QMetaObject const QtAV::VideoPreviewWidget::staticMetaObject" (?staticMetaObject@VideoPreviewWidget@QtAV@@2UQMetaObject@@B)
    

    I compile on VS2017 with Qt5.12 and QtAV1.12.0

    Have you got an idea to solve the problem ?
    Thanks.

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

    Three possibilities (in order of commonality):

    1. You haven't specified the library for linking, or it is not found. See @SGaist's request and provide the project file so we can inspect it.
    2. You and/or the library you're using is missing __declspec(dllimport) and/or __declspec(dllexport) for some reason. Make sure when compiling the library that the relevant macros are defined and list the symbols from the dll so you can make sure they're exported.
    3. You're mixing incompatible compilers - the library is compiled with something e.g. mingw while you're trying to link with msvc (also versions matter).

    Read and abide by the Qt Code of Conduct

    O 1 Reply Last reply
    3
    • SGaistS SGaist

      Hi and welcome to devnet,

      Can you show your .pro file ?

      O Offline
      O Offline
      OPit
      wrote on last edited by
      #4
      This post is deleted!
      1 Reply Last reply
      0
      • O Offline
        O Offline
        OPit
        wrote on last edited by
        #5

        myStream lib

        TARGET = myStream
        DESTDIR = D:/Dev/Programme/myLibs/myStream/lib/ms
        TEMPLATE = lib
        CONFIG += static thread
        QT += widgets avwidgets
        
        UI_HEADERS_DIR = build/ms/h
        OBJECTS_DIR = build/ms/o
        RCC_DIR = build/ms/qrc
        MOC_DIR = build/ms/moc
        INCLUDEPATH = D:/Dev/Programme/3rdparty/ms/include
        LIBS = -LD:/Dev/Programme/3rdparty/ms/lib -lavformat
        
        HEADERS += \
            ../../src/inputstream.h \
            ../../src/dateparser.h \
            ../../src/inputstreammanager.h \
            ../../src/inputstreamcontrol.h \
            ../../src/inputscenecontrol.h \
            ../../src/inputstreamvideo.h \
            ../../src/inputstreampegasus.h \
            ../../src/inputstreaminfo.h \
            ../../src/inputstreamimages.h \
            ../../src/stabilizer.h \
            ../../src/inputstreampreviewslider.h \
            ../../src/inputstreampreview.h
         
        
        SOURCES += \     
            ../../src/inputstream.cpp \
            ../../src/dateparser.cpp \
            ../../src/inputstreammanager.cpp \
            ../../src/inputstreamcontrol.cpp \
            ../../src/inputscenecontrol.cpp \
            ../../src/inputstreamvideo.cpp \
            ../../src/inputstreampegasus.cpp \
            ../../src/inputstreamimages.cpp \
            ../../src/stabilizer.cpp \
            ../../src/inputstreampreviewslider.cpp \
            ../../src/inputstreampreview.cpp
        
        
        

        Application .pro

        QT += network widgets printsupport sql concurrent xml multimedia
        QT += webenginewidgets
        QT += avwidgets
        
        TEMPLATE = app
        DESTDIR = D:/Dev/Programme/AppTest/bin/ms
        VERSION = 4.0
        
        TARGET = AppTest
        DEFINES += TARGET_NAME=\\\"$$TARGET\\\"
        
        RC_FILE = ../../qrc/app.rc
        
        UI_HEADERS_DIR = h
        OBJECTS_DIR = o
        RCC_DIR = qrc
        MOC_DIR = moc
        
        INCLUDEPATH = D:/Dev/Programme/3rdparty/ms/include
        
        LIBS = -LD:/Dev/Programme/3rdparty/ms/lib \
                -lmyGUI \
                -lmyCharts \
                -lmyObject \
                -lmyStyleSheet \
                -lmyScene \
                -lmyStream -lswscale -lavformat -lavcodec -lavutil -lswresample -lws2_32 -lsecur32 \
                -lmyGraphics \
                -lmyCore \
                -lopencv_core400 \
                -lopencv_flann400 -ltbb -lzlib \
                -lgandalf \
                -lexiv2 -llibexpat \
                -llibcrypto \
                -lSMTPEmail \
                -lproj_5_2 \
                -lquazip
        
        RESOURCES += \
            ../../qrc/resource.qrc
        
        SOURCES += \
            ../../src/main.cpp \
            ../../src/core/interface.cpp \
            ../../src/core/core.cpp \
            ../../src/gui/maingui.cpp \
            ../../src/view/playerwidget.cpp \
            ../../src/view/sectionview.cpp \
            ../../src/view/inputstreampreview.cpp
        
        HEADERS += \
            ../../src/core/interface.h \
            ../../src/core/core.h \
            ../../src/gui/maingui.h \
            ../../src/view/playerwidget.h \
            ../../src/view/sectionview.h \
            ../../src/view/frame.h \
            ../../src/view/inputstreampreview.h
        
        1 Reply Last reply
        0
        • kshegunovK kshegunov

          Three possibilities (in order of commonality):

          1. You haven't specified the library for linking, or it is not found. See @SGaist's request and provide the project file so we can inspect it.
          2. You and/or the library you're using is missing __declspec(dllimport) and/or __declspec(dllexport) for some reason. Make sure when compiling the library that the relevant macros are defined and list the symbols from the dll so you can make sure they're exported.
          3. You're mixing incompatible compilers - the library is compiled with something e.g. mingw while you're trying to link with msvc (also versions matter).
          O Offline
          O Offline
          OPit
          wrote on last edited by
          #6

          @kshegunov

          1. QtAV is imported in Qt config, so I think all is good for that (just add QT += avwidgets)
          2. I have thinking about this problem but I don't know how to see if it's OK are not.
          3. I've checked, and it's ok about that.
          kshegunovK 1 Reply Last reply
          0
          • O OPit

            @kshegunov

            1. QtAV is imported in Qt config, so I think all is good for that (just add QT += avwidgets)
            2. I have thinking about this problem but I don't know how to see if it's OK are not.
            3. I've checked, and it's ok about that.
            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #7

            @OPit said in error LNK2001: unresolved external symbol "public: static struct QMetaObject .. from lib template:

            1. QtAV is imported in Qt config, so I think all is good for that (just add QT += avwidgets)

            Did you build that module yourself?

            1. I have thinking about this problem but I don't know how to see if it's OK are not.

            Firstly, use dependency walker to find out what the module links against, from there you could also see what kinds of symbols are exported. Then you can do the same for your library and see if everything matches.

            1. I've checked, and it's ok about that.

            How did you check? Where did you get the qtav module from, or did you compiled it yourself?

            Read and abide by the Qt Code of Conduct

            O 1 Reply Last reply
            2
            • kshegunovK kshegunov

              @OPit said in error LNK2001: unresolved external symbol "public: static struct QMetaObject .. from lib template:

              1. QtAV is imported in Qt config, so I think all is good for that (just add QT += avwidgets)

              Did you build that module yourself?

              1. I have thinking about this problem but I don't know how to see if it's OK are not.

              Firstly, use dependency walker to find out what the module links against, from there you could also see what kinds of symbols are exported. Then you can do the same for your library and see if everything matches.

              1. I've checked, and it's ok about that.

              How did you check? Where did you get the qtav module from, or did you compiled it yourself?

              O Offline
              O Offline
              OPit
              wrote on last edited by
              #8

              @kshegunov Yes, I've built myself the QtAv lib (because the last precompile binaries not use the last version of QtAv).
              I've checked which compiler was used during compilation, and it was the same for each module.

              NB : if I link the moc_inputstreampreview.obj file directly in my app, it works ?!?

              LIBS += path/of/file/moc_inputstreampreview.obj
              
              1 Reply Last reply
              0
              • O Offline
                O Offline
                OPit
                wrote on last edited by
                #9

                If I open QtAvWidget1.dll, I found the function :

                ?metaObject@VideoPreviewWidget@QtAV@@UEBAPEBUQMetaObject@@XZ
                

                I can't read .lib file from dependency walker, how can I check these files ?

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

                  In your build output, can you see whether the QtAV libraries are currently getting linked to your application ?

                  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
                  • O Offline
                    O Offline
                    OPit
                    wrote on last edited by OPit
                    #11

                    Hi,
                    I'm using QtCreator with visual studio compiler and I don't have a lot of informations during linking :

                    link /NOLOGO /DYNAMICBASE /NXCOMPAT /INCREMENTAL:NO /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /VERSION:4.0 /MANIFEST:embed /OUT:..\..\bin\ms\L2R_Video.exe @c:\Temp\L2R_Video.exe.4652.31672.jom
                    myStream.lib(moc_inputstreampreview.obj) : error LNK2001: symbole externe non résolu "public: static struct QMetaObject const QtAV::VideoPreviewWidget::staticMetaObject" (?staticMetaObject@VideoPreviewWidget@QtAV@@2UQMetaObject@@B)
                    ..\..\bin\ms\L2R_Video.exe : fatal error LNK1120: 1 externes non résolus
                    

                    But in my Makefile.Release file, the QtAv libs are well written :

                    LIBS          = /LIBPATH:D:\Dev\Programme\3rdparty\ms\lib 
                    D:\Dev\Programme\3rdparty\ms\lib\myStream.lib 
                    D:\Dev\Programme\3rdparty\ms\lib\swscale.lib 
                    D:\Dev\Programme\3rdparty\ms\lib\avformat.lib 
                    D:\Dev\Programme\3rdparty\ms\lib\avcodec.lib 
                    D:\Dev\Programme\3rdparty\ms\lib\avutil.lib 
                    D:\Dev\Programme\3rdparty\ms\lib\swresample.lib 
                    secur32.lib 
                    D:\Dev\Programme\3rdparty\ms\lib\myGraphics.lib 
                    ws2_32.lib shell32.lib advapi32.lib gdi32.lib User32.lib 
                    /LIBPATH:D:\Dev\Environnement\ms\Qt\5.12.0\msvc2017_64\lib D:\Dev\Environnement\ms\Qt\5.12.0\msvc2017_64\lib\Qt5WebEngineWidgets.lib 
                    D:\Dev\Environnement\ms\Qt\5.12.0\msvc2017_64\lib\Qt5PrintSupport.lib 
                    D:\Dev\Environnement\ms\Qt\5.12.0\msvc2017_64\lib\Qt5AVWidgets.lib 
                    D:\Dev\Environnement\ms\Qt\5.12.0\msvc2017_64\lib\Qt5OpenGL.lib 
                    D:\Dev\Environnement\ms\Qt\5.12.0\msvc2017_64\lib\Qt5Widgets.lib 
                    D:\Dev\Environnement\ms\Qt\5.12.0\msvc2017_64\lib\Qt5Multimedia.lib 
                    D:\Dev\Environnement\ms\Qt\5.12.0\msvc2017_64\lib\Qt5WebEngineCore.lib 
                    D:\Dev\Environnement\ms\Qt\5.12.0\msvc2017_64\lib\Qt5Quick.lib 
                    D:\Dev\Environnement\ms\Qt\5.12.0\msvc2017_64\lib\Qt5AV.lib 
                    ...
                    
                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      Might be a silly question but are linking to libraries of the same type ? Meaning matching debug/release builds.

                      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
                      1
                      • O Offline
                        O Offline
                        OPit
                        wrote on last edited by
                        #13

                        @SGaist said in error LNK2001: unresolved external symbol "public: static struct QMetaObject .. from lib template:

                        silly

                        Sadly it's not the problem ...

                        aha_1980A 1 Reply Last reply
                        0
                        • O OPit

                          @SGaist said in error LNK2001: unresolved external symbol "public: static struct QMetaObject .. from lib template:

                          silly

                          Sadly it's not the problem ...

                          aha_1980A Offline
                          aha_1980A Offline
                          aha_1980
                          Lifetime Qt Champion
                          wrote on last edited by
                          #14

                          @OPit And both have the same architecture, i.e. 32 vs. 64 bit?

                          Qt has to stay free or it will die.

                          O 1 Reply Last reply
                          0
                          • O OPit

                            If I open QtAvWidget1.dll, I found the function :

                            ?metaObject@VideoPreviewWidget@QtAV@@UEBAPEBUQMetaObject@@XZ
                            

                            I can't read .lib file from dependency walker, how can I check these files ?

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

                            This:

                            @OPit said in error LNK2001: unresolved external symbol "public: static struct QMetaObject .. from lib template:

                            ?metaObject@VideoPreviewWidget@QtAV@@UEBAPEBUQMetaObject@@XZ
                            

                            Is very different from this:

                            ?staticMetaObject@VideoPreviewWidget@QtAV@@2UQMetaObject@@B
                            

                            The former is a method, the latter is a (global) variable. Please try again. Could you also provide the content of the moc file in question (the one that fixes the issue if linked with)?

                            Read and abide by the Qt Code of Conduct

                            1 Reply Last reply
                            0
                            • aha_1980A aha_1980

                              @OPit And both have the same architecture, i.e. 32 vs. 64 bit?

                              O Offline
                              O Offline
                              OPit
                              wrote on last edited by OPit
                              #16

                              @aha_1980 yes, the same architecture

                              @kshegunov this is a link to download the file (I can't upload from the forum) :
                              https://we.tl/t-bhEPIToZV2

                              Thanks.

                              kshegunovK 1 Reply Last reply
                              0
                              • hskoglundH Offline
                                hskoglundH Offline
                                hskoglund
                                wrote on last edited by
                                #17

                                Hi, perhaps it's a namespace problem, you could try changing to a using statement in your InputStreamPreview.h:

                                #include <QtAVWidgets/VideoPreviewWidget.h>
                                
                                using namespace QtAV;
                                
                                class InputStreamPreview : public VideoPreviewWidget
                                {
                                Q_OBJECT
                                ...
                                
                                1 Reply Last reply
                                1
                                • O OPit

                                  @aha_1980 yes, the same architecture

                                  @kshegunov this is a link to download the file (I can't upload from the forum) :
                                  https://we.tl/t-bhEPIToZV2

                                  Thanks.

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

                                  @OPit said in error LNK2001: unresolved external symbol "public: static struct QMetaObject .. from lib template:

                                  this is a link to download the file (I can't upload from the forum)

                                  I'm sorry I wasn't clear. I meant the generated moc_XXX.cpp file. I have no tools to inspect the object file even if I wanted to because I work exclusively on Linux.

                                  @hskoglund said in error LNK2001: unresolved external symbol "public: static struct QMetaObject .. from lib template:

                                  Hi, perhaps it's a namespace problem, you could try changing to a using statement in your InputStreamPreview.h

                                  A decent idea, but I don't think that's it. moc, while not too smart, does recognize namespaces and generates code accordingly. I do use them and everything links fine.

                                  Read and abide by the Qt Code of Conduct

                                  1 Reply Last reply
                                  0
                                  • O Offline
                                    O Offline
                                    OPit
                                    wrote on last edited by
                                    #19

                                    @kshegunov oh sorry, this is the cpp file.

                                    https://we.tl/t-NXhNCGkSmc

                                    1 Reply Last reply
                                    0
                                    • hskoglundH Offline
                                      hskoglundH Offline
                                      hskoglund
                                      wrote on last edited by
                                      #20

                                      Hi, do you have a moc_VideoPreviewWidget.cpp that's compiled using Qt 5.12? (The one in the link is built with Qt 5.9.1)

                                      O 1 Reply Last reply
                                      0
                                      • hskoglundH hskoglund

                                        Hi, do you have a moc_VideoPreviewWidget.cpp that's compiled using Qt 5.12? (The one in the link is built with Qt 5.9.1)

                                        O Offline
                                        O Offline
                                        OPit
                                        wrote on last edited by
                                        #21

                                        @hskoglund yes of course : https://we.tl/t-Uhhsre7Vzm

                                        the problem is the same with version 5.9.1 or 5.12 (and also VS2017 or VS2015)

                                        1 Reply Last reply
                                        0
                                        • hskoglundH Offline
                                          hskoglundH Offline
                                          hskoglund
                                          wrote on last edited by
                                          #22

                                          Hi, if you look in the .pro files above for your application and myStream.lib, both .pro files have a inputstreampreview.cpp and a inputstreampreview.h included. They are not located in the same directory (one pair is in ../../src/ and the other pair is in ../../src/view/) but if they have the same contents then maybe the linker gets confused when you build your app (together with your myStream.lib).

                                          If they do not have the same contents (i.e. just a stroke of bad luck with the naming of your files) then rename one of the pairs. Otherwise, you could try building your app again but with only of the pairs, for example commenting out ../../src/view/inputstreampreview.cpp from the SOURCES section in your Application.pro file.

                                          O 1 Reply Last reply
                                          3

                                          • Login

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