Solved Cross-compiling errors linking my own library
-
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
-
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 {};
-
Hi,
Maybe a silly question but are you sure that your custom library is built for the right architecture ?
-
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.
-
Then, are you sure that the library itself is found when linking your Qt application ?
-
- Did you export
myException
in your library? - Can qmake find your library? try adding
LIBS += -L"/home/alex/raspberry/sysroot/usr/lib"
- Did you export
-
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 {};