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

compiling c++ library with web assembly



  • hello,
    I am new to webassembly and qt . I have myown library written in qt called QcStyle.

    and it has a small project call designer. To compile designer it needs QcStyle. But when i place
    insid my makefile all QcStyle .cpp files it gives
    "multiply definition error famous for c++ .

    Since all the ,o files are accessing the same include path , i am having this problem of duplicate.
    Can anyone suggest better ide ahow to compile C++ library in webassembly please and then including in my project.
    Thanks in advance.


  • Moderators

    @Izza said in compiling c++ library with web assembly:

    Can anyone suggest better ide ahow to compile C++ library in webassembly please and then including in my project.

    compile it independently first.
    Then in your main project link against the lib.
    Pretty much the same like you would do in a plain C++/Qt project.



  • I have compiled it, and it has generated all .o files for library

    What i now did is, in my make file plave .o for my library project and created single .o file for it and passed that .o in the linker ...
    But still i need to produce moc_ files aswel... lets see..



  • Can you suggest a script to produce .a file instead .
    And mocing multiple header files of C++
    since moc is not taking multiple header files in one command, I do not want to do menually to many headers.


  • Moderators

    @Izza
    easiest is to create a new .pro file with all sources and specify TEMPLATE=lib
    and also build it with QtWebAssembly



  • My .pro file for library:

    TEMPLATE = lib
    TARGET = QcStyle
    INCLUDEPATH += .
    QTPLUGIN += qjpeg qgif

    The following define makes your compiler warn you if you use any

    feature of Qt which has 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

    Input

    HEADERS += Function.h
    headers.h
    pcheader.h
    Style.h
    Tree.h
    Utilities.h
    Base/Application.h
    Base/BidirectionalBinding.h
    Base/Debug.h
    Base/Font.h
    Base/Function.h
    Base/ItemGrabber.h
    Base/ListModel.h
    Base/Locale.h
    Base/NumberUnit.h
    Base/NumberUnitHelpers.h
    Base/Persistence.h
    Base/SignalWrapper.h
    Base/SmartBinding.h
    Base/Theme.h
    Base/Translator.h
    Base/Unit.h
    Control/Flex.h
    Control/Flickable.h
    Control/Pinchable.h
    Control/SelectGroup.h
    designer/pcheader.h
    designer/version.h
    JSExtension/JSExtension.h
    Layout/MessageLauncher.h
    Misc/Analytics.h
    Misc/ArcGraph.h
    Misc/EdgeGraph.h
    Misc/Hash.h
    Misc/LexerHelpers.h
    Misc/ObjectNotify.h
    Misc/SpaceShortcut.h
    QcStyleUnitTests/Config.h
    QcStyleUnitTests/version.h
    Control/Input/SearchParamModel.h
    Control/Search/CloudTagFilterParams.h
    Control/Search/FilterParams.h
    Control/Search/FilterParamsList.h
    Control/Search/FlipFlopFilterParams.h
    Control/Search/NumberUnitComparatorFilterParams.h
    Control/Search/NumberUnitFilterParams.h
    Control/Search/RangeSliderFilterParams.h
    Control/Search/ScoreFilterParams.h
    Control/Search/SearchModel.h
    Control/Search/SearchParams.h
    Control/Search/SortParams.h
    Control/Search/SpinBoxFilterParams.h
    designer/Test/SGTest.h
    SOURCES += pcheader.cpp
    Style.cpp
    Utilities.cpp
    Base/Application.cpp
    Base/BidirectionalBinding.cpp
    Base/Debug.cpp
    Base/Font.cpp
    Base/ItemGrabber.cpp
    Base/ListModel.cpp
    Base/Locale.cpp
    Base/NumberUnit.cpp
    Base/NumberUnitHelpers.cpp
    Base/Persistence.cpp
    Base/SignalWrapper.cpp
    Base/SmartBinding.cpp
    Base/Theme.cpp
    Base/Translator.cpp
    Base/Unit.cpp
    Control/Flex.cpp
    Control/Flickable.cpp
    Control/Pinchable.cpp
    Control/SelectGroup.cpp
    designer/designer_plugin_import.cpp
    designer/main.cpp
    JSExtension/JSExtension.cpp
    Misc/Analytics.cpp
    Misc/LexerHelpers.cpp
    Misc/ObjectNotify.cpp
    Misc/SpaceShortcut.cpp
    QcStyleUnitTests/ArcGraph.cpp
    QcStyleUnitTests/main.cpp
    Control/Input/SearchParamModel.cpp
    Control/Search/CloudTagFilterParams.cpp
    Control/Search/FilterParams.cpp
    Control/Search/FilterParamsList.cpp
    Control/Search/FlipFlopFilterParams.cpp
    Control/Search/NumberUnitComparatorFilterParams.cpp
    Control/Search/NumberUnitFilterParams.cpp
    Control/Search/RangeSliderFilterParams.cpp
    Control/Search/ScoreFilterParams.cpp
    Control/Search/SearchModel.cpp
    Control/Search/SearchParams.cpp
    Control/Search/SortParams.cpp
    Control/Search/SpinBoxFilterParams.cpp
    designer/Test/SGTest.cpp
    TRANSLATIONS += translations/Strings.ar.ts
    translations/Strings.de.ts
    translations/Strings.es.ts
    translations/Strings.fr.ts
    translations/Strings.he.ts
    translations/Strings.it.ts
    translations/Strings.ja.ts
    translations/Strings.ko.ts
    translations/Strings.pl.ts
    translations/Strings.pt.ts
    translations/Strings.ru.ts
    translations/Strings.tr.ts
    translations/Strings.ts
    translations/Strings.zh_CN.ts
    translations/Strings.zh_TW.ts



  • ok I have created .a file but how to link it with project now?


  • Moderators



  • Thanks alot


Log in to reply