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. Problem with my C++ library that uses a interface class[Solved]
Forum Updated to NodeBB v4.3 + New Features

Problem with my C++ library that uses a interface class[Solved]

Scheduled Pinned Locked Moved General and Desktop
15 Posts 3 Posters 4.5k Views 1 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.
  • M Offline
    M Offline
    maxoreli
    wrote on last edited by
    #6

    [quote author="Volker" date="1325265231"]You showed the source code. Object code is what the compiler produces. It's glued together by the linker to a runnable application (or a library).

    Just by including the header file into another source file does not necessarily produce some object code that can be linked. I recommend to put the dummy implementation of the interface into a separate C++ file (.cpp). You will have to link its object code (xxx.o) to your project or - better - create a library out of it that you link against.[/quote]

    How do i will do that,making dummy implementation.
    Create an another source file nammed 'TableManagerInterface.cpp' and put this code?
    @
    #include "TableManagerInterface.h"
    @
    i try it but dont work.
    Please lead me to do it..
    thanks in advance

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #7

      You will have to move the empty body of the destructor to the .cpp file. And either include that file into your plugin project, or make it a library that you link against. I don't have a complete example at hand.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maxoreli
        wrote on last edited by
        #8

        i did what you said and compilation works fine.
        Now i want to use my C++ library in another project .

        this is global structure of my project.

        -Folder Dao(Dao.pro,
        Folder ITableManager(itablemanager.pro,itablemanager.h,itablemanager.cpp,
        Folder interface(TableManagerInterface.h,TableManagerInterface.cpp))
        )

        -Folder ui(project which uses library class)
        (
        ui.pro, dialogArtiste.cpp,dialogArtiste.h
        )

        Now i edit the * ui.pro* file for using library.
        @

        QT +=sql

        SOURCES +=
        main.cpp

        #folders
        include(client/client.pri)
        include(contrat/contrat.pri)
        include(reservation/reservation.pri)
        include(suivi_formation/suivi_formation.pri)
        include(suivi_master/suivi_master.pri)
        include(ventes/ventes.pri)

        #library
        DEPENDPATH += Dao/ITableManager
        INCLUDEPATH += Dao/ITableManager
        LIBS += -LDao/ITableManager/debug -lITableManager

        @

        -in some parts in dialogArtiste.h i m putting following codes(i include 'itablemanager.h' and declare a 'ITableManager object')

        @
        #ifndef DIALOGARTISTE_H
        #define DIALOGARTISTE_H

        #include "ui_dialogartiste.h"

        //include for using ITableManager class
        #include "itablemanager.h"

        class DialogArtiste : public QDialog, private Ui::DialogArtiste
        {
        Q_OBJECT

        public:
        explicit DialogArtiste(QWidget *parent = 0);

        protected:
        void changeEvent(QEvent *e);
        private:
        ITableManager *manager; // declare a ITableManager(class of my library)
        };

        #endif // DIALOGARTISTE_H

        @

        then when i compile, i'm getting error like:

        :-1: error: cannot find -lITableManager
        i think that i dont put an appropriate path of my library.
        What do i should do?
        Thanks in advance.

        [quote author="Volker" date="1325338845"]You will have to move the empty body of the destructor to the .cpp file. And either include that file into your plugin project, or make it a library that you link against. I don't have a complete example at hand.[/quote]

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #9

          [quote author="maxoreli" date="1325660608"]
          then when i compile, i'm getting error like:

          :-1: error: cannot find -lITableManager
          i think that i dont put an appropriate path of my library.
          What do i should do?
          Thanks in advance.
          [/quote]

          Search the location of libTableManager.{a,so,lib,dylib} and add this directory to the LIBS variable:

          @
          LIBS += -L/path/to/your/lib
          @

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • M Offline
            M Offline
            maxoreli
            wrote on last edited by
            #10

            ok,i have done it like that.
            @
            DEPENDPATH += C:/Users/MAXORELI/Documents/QtPrograms/ENIOLASYST/Dao/ITableManager
            INCLUDEPATH += C:/Users/MAXORELI/Documents/QtPrograms/ENIOLASYST/Dao/ITableManager
            LIBS += -L/C:/Users/MAXORELI/Documents/QtPrograms/ENIOLASYST_Debug/Dao/lib/libITableManagerPlugin.a
            @
            However, i m getting following error:
            \dialogartiste.o:-1: In function DialogArtiste': \dialogartiste.cpp:8: error: undefined reference to _imp___ZN13ITableManagerC1Ev'
            \dialogartiste.cpp:8: error: undefined reference to `_imp___ZN13ITableManagerC1Ev'

            what happens i dont understand
            [quote author="Volker" date="1325691249"]
            [quote author="maxoreli" date="1325660608"]
            then when i compile, i'm getting error like:

            :-1: error: cannot find -lITableManager
            i think that i dont put an appropriate path of my library.
            What do i should do?
            Thanks in advance.
            [/quote]

            Search the location of libTableManager.{a,so,lib,dylib} and add this directory to the LIBS variable:

            @
            LIBS += -L/path/to/your/lib
            @
            [/quote]

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #11

              That's basic C/C++ magic

              • -L (uppercase L) adds the path to a directory containing libraries
              • -l (lowercase l) add a library to the link step
                it is search in the standard system lib paths and that added via -L to your project

              I leave it as an exercise to you to split your line up into two parts.

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • M Offline
                M Offline
                maxoreli
                wrote on last edited by
                #12

                -in fact my lines aren't splitted in my .pro file, they were splitted when i have posted the reply.
                this is what happens.
                when i just declare an ITableManager in .h file ,compilation works fine.

                @
                #ifndef DIALOGARTISTE_H
                #define DIALOGARTISTE_H

                #include "ui_dialogartiste.h"
                #include "itablemanager.h"

                class DialogArtiste : public QDialog, private Ui::DialogArtiste
                {
                Q_OBJECT

                public:
                explicit DialogArtiste(QWidget *parent = 0);

                protected:
                void changeEvent(QEvent *e);
                private:
                ITableManager *manager;
                };

                #endif // DIALOGARTISTE_H
                @

                after when i instantiate the ITableManager in .cpp, compilation displays errors:

                @
                #include "dialogartiste.h"

                DialogArtiste::DialogArtiste(QWidget *parent) :
                QDialog(parent)
                {
                setupUi(this);

                manager=new ITableManager;
                

                }
                @

                Errors:
                -dialogartiste.cpp:8: error: undefined reference to_imp___ZN13ITableManagerC1Ev' -dialogartiste.cpp:8: error: undefined reference to _imp___ZN13ITableManagerC1Ev'
                [quote author="Volker" date="1325780670"]That's basic C/C++ magic

                • -L (uppercase L) adds the path to a directory containing libraries
                • -l (lowercase l) add a library to the link step
                  it is search in the standard system lib paths and that added via -L to your project

                I leave it as an exercise to you to split your line up into two parts.[/quote]

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #13

                  @
                  LIBS += LC:/Users/MAXORELI/Documents/QtPrograms/ENIOLASYST_Debug/Dao/lib
                  LIBS + -lITableManagerPlugin
                  @

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    maxoreli
                    wrote on last edited by
                    #14

                    oh,thanks you so much Volker,really speaking i was so stupid for not thinking to it,now compilation works fine,but isn't it some parts where it is explained in documentation? if yes,send me link,or you have an another link which explains this notion.
                    How to mark this thread like resolved?
                    Thanks for reading again.
                    [quote author="Volker" date="1325810603"]@
                    LIBS += LC:/Users/MAXORELI/Documents/QtPrograms/ENIOLASYST_Debug/Dao/lib
                    LIBS + -lITableManagerPlugin
                    @
                    [/quote]

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      goetz
                      wrote on last edited by
                      #15

                      It's not in the Qt docs (despite some usage in examples). It's compiler dependent and documented with those, although most tool chains use -l and -L for the libs and lib paths, and -I for include paths. I don't know of any popular compiler that doesn't support this (at least additionally to some "native" switches like /xxx). It should be explained detailed in quite all decent introductions into C/C++ programming.

                      To mark a thread as solved, just go to your very first post that opened the thread, click on the edit link right to it (just below your username and avatar) and prepend [Solved] to your topic, that's all. You might want to add a tag "solved" too.

                      http://www.catb.org/~esr/faqs/smart-questions.html

                      1 Reply Last reply
                      0

                      • Login

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