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. C++ constant static vector instantiation
QtWS25 Last Chance

C++ constant static vector instantiation

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 5 Posters 949 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.
  • faiszalkhanF Offline
    faiszalkhanF Offline
    faiszalkhan
    wrote on last edited by
    #1

    I'm interfacing an external library with QT Desktop App. Since I'm on QT creator 4.3.1, it has a bug for adding external libraries to project. I have manually added the library in the .pro file and included the headers in my project.

    In one of the files A.h, A static vector is initialised in a class declaration. The Project compiles successfully when I do not include this file in any other file. But, I get the error(pasted below the class declaration) when I include it any of my files.

    The static Vector LICENSE_ISSUING_AUTHORITIES of IssuingAuthority objects is initialised in the header file with one IssuingAuthority object in the header file.

    A.h

    class LicenseManagerKeyRegister
    {
    public:
    
        static const unsigned char LICENSE_MANAGER_SIGNATURE_KEY[];
    
        static const std::vector<IssuingAuthority> LICENSE_ISSUING_AUTHORITIES;
    };
    
    const unsigned char LicenseManagerKeyRegister::LICENSE_MANAGER_SIGNATURE_KEY[] =
    {
        0x82, 0xF3, 0x6C, 0x25, 0xA9, 0x12, 0x38, 0x9A, 0xBF, 0xF8, 0x09, 0x1C, 0x75, 0x93, 0x03, 0xD2
    };
    
    const std::vector<IssuingAuthority> LicenseManagerKeyRegister::LICENSE_ISSUING_AUTHORITIES = {
        IssuingAuthority("String_1", "String_2", "LS0tLS1C", 24, true), // 1 day - no-secret
    };
    
    

    Error Text:

    ndefined symbols for architecture x86_64:
      "licensepp::IssuingAuthority::IssuingAuthority(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned int, bool)", referenced from:
          ___cxx_global_var_init in licenseinterface.o
      "licensepp::IssuingAuthority::IssuingAuthority(licensepp::IssuingAuthority const&)", referenced from:
          std::__1::enable_if<__is_forward_iterator<licensepp::IssuingAuthority const*>::value, void>::type std::__1::vector<licensepp::IssuingAuthority, std::__1::allocator<licensepp::IssuingAuthority> >::__construct_at_end<licensepp::IssuingAuthority const*>(licensepp::IssuingAuthority const*, licensepp::IssuingAuthority const*, unsigned long) in licenseinterface.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    

    Issuing Authority Constructor:

    IssuingAuthority(const std::string& id, const std::string& name,
                     const std::string& keypair, unsigned int maxValidity,
                     bool active = true)
    

    I checked if it is an issue with signature matching with the IssuingAuthority constructor as the error suggests but it doesn't seem to me to be the error.

    Any help would be appreciated.

    Thanks.

    jsulmJ 1 Reply Last reply
    0
    • faiszalkhanF faiszalkhan

      I'm interfacing an external library with QT Desktop App. Since I'm on QT creator 4.3.1, it has a bug for adding external libraries to project. I have manually added the library in the .pro file and included the headers in my project.

      In one of the files A.h, A static vector is initialised in a class declaration. The Project compiles successfully when I do not include this file in any other file. But, I get the error(pasted below the class declaration) when I include it any of my files.

      The static Vector LICENSE_ISSUING_AUTHORITIES of IssuingAuthority objects is initialised in the header file with one IssuingAuthority object in the header file.

      A.h

      class LicenseManagerKeyRegister
      {
      public:
      
          static const unsigned char LICENSE_MANAGER_SIGNATURE_KEY[];
      
          static const std::vector<IssuingAuthority> LICENSE_ISSUING_AUTHORITIES;
      };
      
      const unsigned char LicenseManagerKeyRegister::LICENSE_MANAGER_SIGNATURE_KEY[] =
      {
          0x82, 0xF3, 0x6C, 0x25, 0xA9, 0x12, 0x38, 0x9A, 0xBF, 0xF8, 0x09, 0x1C, 0x75, 0x93, 0x03, 0xD2
      };
      
      const std::vector<IssuingAuthority> LicenseManagerKeyRegister::LICENSE_ISSUING_AUTHORITIES = {
          IssuingAuthority("String_1", "String_2", "LS0tLS1C", 24, true), // 1 day - no-secret
      };
      
      

      Error Text:

      ndefined symbols for architecture x86_64:
        "licensepp::IssuingAuthority::IssuingAuthority(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned int, bool)", referenced from:
            ___cxx_global_var_init in licenseinterface.o
        "licensepp::IssuingAuthority::IssuingAuthority(licensepp::IssuingAuthority const&)", referenced from:
            std::__1::enable_if<__is_forward_iterator<licensepp::IssuingAuthority const*>::value, void>::type std::__1::vector<licensepp::IssuingAuthority, std::__1::allocator<licensepp::IssuingAuthority> >::__construct_at_end<licensepp::IssuingAuthority const*>(licensepp::IssuingAuthority const*, licensepp::IssuingAuthority const*, unsigned long) in licenseinterface.o
      ld: symbol(s) not found for architecture x86_64
      clang: error: linker command failed with exit code 1 (use -v to see invocation)
      

      Issuing Authority Constructor:

      IssuingAuthority(const std::string& id, const std::string& name,
                       const std::string& keypair, unsigned int maxValidity,
                       bool active = true)
      

      I checked if it is an issue with signature matching with the IssuingAuthority constructor as the error suggests but it doesn't seem to me to be the error.

      Any help would be appreciated.

      Thanks.

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @faiszalkhan Do you link against the lib? Please show your pro file.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • faiszalkhanF Offline
        faiszalkhanF Offline
        faiszalkhan
        wrote on last edited by faiszalkhan
        #3

        @jsulm Yes I did.:

        #-------------------------------------------------
        #
        # Project created by QtCreator 2017-09-24T00:59:21
        #
        #-------------------------------------------------
        
        QT       += core gui
        
        greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
        
        TARGET = RapidFSM
        TEMPLATE = app
        
        ICON = Images/app_icon.png
        
        
        # The following define makes your compiler emit warnings if you use
        # any feature of Qt which as been marked as deprecated (the exact warnings
        # depend on your compiler). Please consult the documentation of the
        # deprecated API in order to know how to port your code away from it.
        DEFINES += QT_DEPRECATED_WARNINGS
        
        # You can also make your code fail to compile if you use deprecated APIs.
        # In order to do so, uncomment the following line.
        # You can also select to disable deprecated APIs only up to a certain version of Qt.
        #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
        
        #Added after implementing the new folder structure
        INCLUDEPATH += src/header \
        
        LIBS += -L/Users/faisalkhan/Documents/GIT/RapidFSM/RapidFSM/third_party/license++/exe/
        
        
        SOURCES += \
            src/source/main.cpp \
            src/source/mainwindow.cpp \
            src/source/createproject.cpp \
            src/source/openproject.cpp \
            src/source/treemodel.cpp \
            src/source/treeitem.cpp \
            src/source/stateitem.cpp \
            src/source/canvas.cpp \
            src/source/stateproperties.cpp \
            src/source/transitionproperties.cpp \
            src/source/transitionItem.cpp \
            src/source/transitionline.cpp \
            src/source/projectmodelio.cpp \
            src/source/xmlio.cpp \
            src/source/textitem.cpp \
            src/source/textproperties.cpp \
            src/source/linkitem.cpp \
            src/source/canvassize.cpp \
            src/source/processitem.cpp \
            src/source/processproperties.cpp \
            src/source/memoryitem.cpp \
            src/source/linkline.cpp \
            src/source/linkproperties.cpp \
            src/source/floatinglinkitem.cpp \
            src/source/memoryproperties.cpp \
            src/source/dataflowitem.cpp \
            src/source/dataflowline.cpp \
            src/source/dataflowproperties.cpp \
            src/source/floatingmemory.cpp \
            src/source/codegenerator.cpp \
            src/source/codegenproperties.cpp \
            src/source/runguard.cpp \
            src/source/codegenerrorlog.cpp \
            src/source/statecommands.cpp \
            src/source/transitioncommands.cpp \
            src/source/textcommands.cpp \
            src/source/memorycommands.cpp \
            src/source/licensemanager.cpp \
            src/source/licenseinterface.cpp
        
        
        HEADERS += \
            src/header/mainwindow.h \
            src/header/createproject.h \
            src/header/openproject.h \
            src/header/treemodel.h \
            src/header/treeitem.h \
            src/header/common.h \
            src/header/stateitem.h \
            src/header/canvas.h \
            src/header/stateproperties.h \
            src/header/transitionproperties.h \
            src/header/transitionItem.h \
            src/header/transitionline.h \
            src/header/projectmodelio.h \
            src/header/xmlio.h \
            src/header/textitem.h \
            src/header/textproperties.h \
            src/header/linkitem.h \
            src/header/canvassize.h \
            src/header/processitem.h \
            src/header/processproperties.h \
            src/header/memoryitem.h \
            src/header/linkline.h \
            src/header/linkproperties.h \
            src/header/floatinglinkitem.h \
            src/header/memoryproperties.h \
            src/header/dataflowitem.h \
            src/header/dataflowline.h \
            src/header/dataflowproperties.h \
            src/header/floatingmemory.h \
            src/header/codegenerator.h \
            src/header/codegenproperties.h \
            src/header/runguard.h \
            src/header/codegenerrorlog.h \
            src/header/statecommands.h \
            src/header/transitioncommands.h \
            src/header/textcommands.h \
            src/header/memorycommands.h \
            src/header/licensemanager.h \
            src/header/licenseinterface.h \
            third_party/license++/base-license-manager.h \
            third_party/license++/issuing-authority.h \
            third_party/license++/license-exception.h \
            third_party/license++/license.h
        
        FORMS += \
            src/forms/mainwindow.ui \
            src/forms/createproject.ui \
            src/forms/openproject.ui \
            src/forms/stateproperties.ui \
            src/forms/transitionproperties.ui \
            src/forms/textproperties.ui \
            src/forms/canvassize.ui \
            src/forms/processproperties.ui \
            src/forms/linkproperties.ui \
            src/forms/memoryproperties.ui \
            src/forms/dataflowproperties.ui \
            src/forms/codegenproperties.ui \     
            src/forms/codegenerrorlog.ui
        
        
        RESOURCES += \
            resource/res.qrc
        
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          AFAICS, no you are not. You seem to only have passed the path to where the library is located but you don't link to it.

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

          faiszalkhanF 1 Reply Last reply
          4
          • SGaistS SGaist

            Hi,

            AFAICS, no you are not. You seem to only have passed the path to where the library is located but you don't link to it.

            faiszalkhanF Offline
            faiszalkhanF Offline
            faiszalkhan
            wrote on last edited by
            #5

            @SGaist Can you please provide a link to an article/Documentation which you think would help me out. Thank you very much.

            jsulmJ 1 Reply Last reply
            0
            • faiszalkhanF faiszalkhan

              @SGaist Can you please provide a link to an article/Documentation which you think would help me out. Thank you very much.

              jsulmJ Online
              jsulmJ Online
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @faiszalkhan https://doc.qt.io/qt-5/third-party-libraries.html
              Hint: -lLIBNAME is missing in your pro file.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              faiszalkhanF 1 Reply Last reply
              4
              • jsulmJ jsulm

                @faiszalkhan https://doc.qt.io/qt-5/third-party-libraries.html
                Hint: -lLIBNAME is missing in your pro file.

                faiszalkhanF Offline
                faiszalkhanF Offline
                faiszalkhan
                wrote on last edited by
                #7

                @jsulm @SGaist I checked the documentation, found it straightforward and made the changes but I'm still not able to get past this issue. I changed the command to :

                LIBS += -L"third_party/license++/exe" -lliblicensepp
                

                I'm compiling on macOS with QT creator 5.9. I tried all the permutations and combinations for the path but it doesn't seem to work.

                Error :

                ld: warning: directory not found for option '-Lthird_party/license++/exe'
                ld: library not found for -lliblicensepp
                clang: error: linker command failed with exit code 1 (use -v to see invocation)
                

                Please help.

                1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @faiszalkhan said in C++ constant static vector instantiation:

                  LIBS += -L"third_party/license++/exe" -lliblicensepp

                  Hint: -lLIBNAME is missing in your pro file.

                  I don't think your libname is '-L"third_party/license++/exe" -lliblicensepp' but licensepp ...

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

                  faiszalkhanF 1 Reply Last reply
                  1
                  • Christian EhrlicherC Christian Ehrlicher

                    @faiszalkhan said in C++ constant static vector instantiation:

                    LIBS += -L"third_party/license++/exe" -lliblicensepp

                    Hint: -lLIBNAME is missing in your pro file.

                    I don't think your libname is '-L"third_party/license++/exe" -lliblicensepp' but licensepp ...

                    faiszalkhanF Offline
                    faiszalkhanF Offline
                    faiszalkhan
                    wrote on last edited by
                    #9

                    @Christian-Ehrlicher The name of the library is liblicensepp.dylib. I have prepended "-l" as mentioned in the documentation mentioned above.

                    1 Reply Last reply
                    0
                    • Kent-DorfmanK Offline
                      Kent-DorfmanK Offline
                      Kent-Dorfman
                      wrote on last edited by
                      #10

                      when using -l{libname} you don't generally write -llib{libname} but just -l{libname}

                      -lmath is right, where -llibmath is wrong

                      1 Reply Last reply
                      3
                      • faiszalkhanF Offline
                        faiszalkhanF Offline
                        faiszalkhan
                        wrote on last edited by
                        #11

                        @Kent-Dorfman Thank you for that. I made the change as follows

                        LIBS += -L"third_party/license++/exe" -llicensepp
                        

                        Same error :(

                        1 Reply Last reply
                        0
                        • Christian EhrlicherC Offline
                          Christian EhrlicherC Offline
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          The name of the library is liblicensepp.dylib.

                          No, the name is licensepp, the filename of the library is 'liblicensepp.dylib' (or 'liblicensepp.so' on linux or licensepp.dll on windows).

                          The directory should be absolute or correctly relative (which isn't as the compiler tells you).

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

                          1 Reply Last reply
                          2
                          • faiszalkhanF Offline
                            faiszalkhanF Offline
                            faiszalkhan
                            wrote on last edited by
                            #13

                            @Christian-Ehrlicher thanks. Providing the absolute path worked. However, I'm not sure why the relative directory path doesn't work as it is straight forward. The relative path I give is relative wrt the .pro file as has been done for the headers and sources.

                            1 Reply Last reply
                            0
                            • Christian EhrlicherC Offline
                              Christian EhrlicherC Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @faiszalkhan said in C++ constant static vector instantiation:

                              relative wrt the .pro file as has been done for the headers and sources.

                              it must be the relative one on where the linker is called.

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

                              1 Reply Last reply
                              1
                              • faiszalkhanF Offline
                                faiszalkhanF Offline
                                faiszalkhan
                                wrote on last edited by faiszalkhan
                                #15

                                @jsulm @SGaist @Christian-Ehrlicher @Kent-Dorfman Thank you very much.

                                1 Reply Last reply
                                1

                                • Login

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