Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

C++ constant static vector instantiation



  • 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.


  • Qt Champions 2019

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



  • @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
    
    

  • Lifetime Qt Champion

    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.



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


  • Qt Champions 2019

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



  • @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.


  • Qt Champions 2019

    @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 ...



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



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

    -lmath is right, where -llibmath is wrong



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

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

    Same error :(


  • Qt Champions 2019

    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).



  • @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.


  • Qt Champions 2019

    @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.




Log in to reply