Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. QtonPi
  4. Cross-compiling errors linking my own library
Forum Updated to NodeBB v4.3 + New Features

Cross-compiling errors linking my own library

Scheduled Pinned Locked Moved Solved QtonPi
6 Posts 3 Posters 3.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.
  • A Offline
    A Offline
    AlTro
    wrote on last edited by
    #1

    Hi,
    I cross-compiled qt5.7 with gcc4.7 linaro toolchain with no problems (I compiled many examples and all work)
    After that I compiled my own library and all is ok, but when I tried to compile a project that links my library I got these errors:

    /home/alex/sources/main.cpp:54:error: undefined reference to `typeinfo for mynamespace::myException'
    
    /home/alex/sources/main.cpp:54:error: undefined reference to `mynamespace::myException::~myException()'
    
    /home/alex/raspberry/sysroot/usr/lib/mylib.so: error: undefined reference to `vtable for mynamespace::myException'
    
    collect2: error: ld returned 1 exit status
    

    This is my .pro

    CONFIG      +=  debug_and_release
    
    QMAKE_CXXFLAGS += -std=c++11
    
    QT  -= gui
    QT  += dbus
    
    SOURCES     += src/main.cpp \
                    src/wd.cpp
    
    HEADERS     += include/wd.h
    
    LIBS        +=  -lmylib
    INCLUDEPATH += include
    DEPENDPATH  += /home/alex/raspberry/sysroot/usr/lib
    
    OBJECTS_DIR = obj
    MOC_DIR     = moc
    DESTDIR     = bin
    
    TARGET  =   wd
    build_pass:CONFIG(debug, debug|release) {
        TARGET = $$join(TARGET,,,_debug)
    }
    
    target.path = /home/pi/dev/wd
    INSTALLS += target
    

    I think the problem is that the compiler doesn't find include files (that are in sysroot/usr/include) and the library (that is in sysroot/usr/lib).
    I also controlled the compilation command in Qt Creator and it seems to be right.

    How can I set properly the project to link my shared library? And if I have to link another third party library (like mosquitto)?

    Thanks in advance

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AlTro
      wrote on last edited by
      #6

      The problem was because the cross-compilation is done with gcc4.7, that doesn't have full c++11 support, but the test compilation on the raspberry whit gcc4.9.

      Because of this I changed the declaration of the destructor mynamespace::myException::~myException() adding "noexcept".

      namespace mynamespace {
          class myException : public std::exception
          {
              public:
                  myException( std::string whatHappened );
                  virtual ~myException() noexcept;
                  virtual const char* what() const throw();
      
              protected:
                  std::string _whatHappened;
      
              private:
                  static const std::string EXCEPTION_NAME;
          };
      }
      

      In .cpp the descructor was implemented but gcc4.7 want an inline implementation, so adding this to .h file and compiling all works.

                 virtual ~myException() noexcept {};
      
      1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        Maybe a silly question but are you sure that your custom library is built for the right architecture ?

        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
        • A Offline
          A Offline
          AlTro
          wrote on last edited by
          #3

          Yes, I cross-compiled the library with without problems. I also deployed the lib on the raspberry and test it with a little software compiled directly on raspberry. All works great.

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

            Then, are you sure that the library itself is found when linking your Qt 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
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #5
              • Did you export myException in your library?
              • Can qmake find your library? try adding LIBS += -L"/home/alex/raspberry/sysroot/usr/lib"

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              1
              • A Offline
                A Offline
                AlTro
                wrote on last edited by
                #6

                The problem was because the cross-compilation is done with gcc4.7, that doesn't have full c++11 support, but the test compilation on the raspberry whit gcc4.9.

                Because of this I changed the declaration of the destructor mynamespace::myException::~myException() adding "noexcept".

                namespace mynamespace {
                    class myException : public std::exception
                    {
                        public:
                            myException( std::string whatHappened );
                            virtual ~myException() noexcept;
                            virtual const char* what() const throw();
                
                        protected:
                            std::string _whatHappened;
                
                        private:
                            static const std::string EXCEPTION_NAME;
                    };
                }
                

                In .cpp the descructor was implemented but gcc4.7 want an inline implementation, so adding this to .h file and compiling all works.

                           virtual ~myException() noexcept {};
                
                1 Reply Last reply
                2

                • Login

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