Qt 5.14.2 does not file .so file when building - c++

I struggle for cross compiling for Raspberry pi 4. My OS is Ubuntu 20.04. I builded cross compile platform and I have been run simple quick application. (I created project on PC and I could see output window on Raspberry pi screen).
I want run more big project on Raspberry pi4 with cross compile. I want edit code on my PC and I want see output on Raspberry pi 4. I have been worked this project on Raspberry pi 4 without Qt.
I tried run qmake for .pro file and I compiled the resulting makefile file. It's working. I want do same process with cross compile but I have errors this place. Qt does not find some .so files but I checked and this files are exist on the specified path. I tried add external library,I tried add external library and I tried editing path of LIBS and INCLUDEPATH but result did not change.
P.S. I used this commands when I building cross compile. https://github.com/PhysicsX/QTonRaspberryPi/blob/main/qt5.14.2onRaspberrypi
My .pro file is:
QT += quick widgets serialport multimedia
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Refer to the documentation for the
# deprecated API to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
INCLUDEPATH += -I/opt/qt5pi/sysroot/usr/include/opencv2
LIBS += -L/opt/qt5pi/sysroot/usr/lib -lopencv_core -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_videostab -lopencv_features2d
# You can also make your code fail to compile if it uses 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
SOURCES += \
main.cpp \
file.cpp \
gcodesender.cpp \
movementmanager.cpp \
usbmanager.cpp \
imageresizer.cpp \
serialcommunicator.cpp \
frameprocessor.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /home/pi/dev/$${TARGET}/
!isEmpty(target.path): INSTALLS += target
HEADERS += \
file.h \
gcodesender.h \
movementmanager.h \
usbmanager.h \
imageresizer.h \
serialcommunicator.h \
frameprocessor.h
DISTFILES += \
theme/DarkTheme_copy.qml \
theme/WhiteTheme.qml
Part of the error is below:
linux-gnueabihf/libavformat.so.58, not found (try using -rpath or -rpath-link)
/opt/qt5pi/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/7.5.0/../../../../arm-linux-gnueabihf/bin/ld: warning: libvcos.so, needed by /opt/qt5pi/sysroot/usr/lib/arm-linux-gnueabihf/libavformat.so.58, not found (try using -rpath or -rpath-link)
/opt/qt5pi/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/7.5.0/../../../../arm-linux-gnueabihf/bin/ld: warning: libblas.so.3, needed by /opt/qt5pi/sysroot/lib/libarmadillo.so.9, not found (try using -rpath or -rpath-link)
/opt/qt5pi/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/7.5.0/../../../../arm-linux-gnueabihf/bin/ld: warning: liblapack.so.3, needed by /opt/qt5pi/sysroot/lib/libarmadillo.so.9, not found (try using -rpath or -rpath-link)
/opt/qt5pi/sysroot/lib/libarmadillo.so.9: undefined reference to `zgemm_'
/opt/qt5pi/sysroot/usr/lib/arm-linux-gnueabihf/libarpack.so.2: undefined reference to `clahqr_'
/opt/qt5pi/sysroot/lib/libarmadillo.so.9: undefined reference to `sdot_'
/opt/qt5pi/sysroot/usr/lib/arm-linux-gnueabihf/libavcodec.so.58: undefined reference to `vcsm_malloc_cache'
/opt/qt5pi/sysroot/lib/libarmadillo.so.9: undefined reference to `dgehrd_'
/opt/qt5pi/sysroot/lib/libarmadillo.so.9: undefined reference to `zgetrf_'
/opt/qt5pi/sysroot/lib/libarmadillo.so.9: undefined reference to `zggev_'
And my compiled output all errors(I'm stuck on the character limit ): https://pastebin.pl/view/cbeede8a
How can I fix error ?
Thanks

Related

compilation error of OpenCV cpp code using Qt

I am using a very basic OpenCV code to compile using Qt but every time the following errors are coming.
OpenCV version
OpenCV version : 3.4.3
Major version : 3
Minor version : 4
Subminor version : 3
My code
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"
using namespace std;
using namespace cv;
int main()
{
Mat I = imread("path/filename.ppm", 1);
imshow("conv_image",I);
waitKey();
return 0;
}
.pro file
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
# The following define makes your compiler emit warnings if you
use
# any feature of Qt which as been marked 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
SOURCES += main.cpp
INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -
lopencv_highgui
Given Error
:-1: warning: libopencv_core.so.3.4, needed by /usr/local/lib/libopencv_imgcodecs.so, may conflict with libopencv_core.so.2.4
:-1: error: main.o: undefined reference to symbol '_ZN2cv6String10deallocateEv'
/usr/local/lib/libopencv_core.so.3.4:-1: error: error adding symbols: DSO missing from command line
:-1: error: collect2: error: ld returned 1 exit status
In my .pro file, I have used the following line(from the different link I have found 3 ways, I have tried all but failed)
First
INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -
lopencv_highgui
Second
INCLUDEPATH +=/usr/local/include/opencv
LIBS +=`pkg-config --libs opencv`
Third
I have used information from here
Please give me suggestion to solve the issue.

Linking OpenCV to a shared library "mylib", `undefined reference to ...` errors

I am trying to use OpenCV-2.4.13 shared objects (libopencv_core.so,libopencv_imgproc.so etc.) in mylib.so.
These OpenCV shared objects are compiled and installed with standard build procedure (make, make install) and I confirmed that they are located in /usr/local/lib, they can be used directly with an application without any problem.
I am using Qt 5.8 on Ubuntu 16.04 for building process.
In mylib.so, I use common cv::Mat functions. Looking at the similar questions, I have already skimmed this article, it suggests either using -rpath or -rpath-link options during linking mylib.so with an application. I also did read this article from Qt and applied the suggested method when building mylib.so: adding a a_global.h and defining an export symbol as Q_DECL_EXPORT.
I am providing .pro file for mylib.so below.
QT -= gui
CONFIG += c++11
TARGET = mylib
TEMPLATE = lib
DEFINES += MYLIB_LIBRARY
SOURCES += a.cpp
HEADERS += a.h external_libraries.h a_global.h
unix {
target.path = /usr/lib
INSTALLS += target
}
INCLUDEPATH += "/usr/local/include"
LIBS += -L/usr/local/lib -lopencv_calib3d -lopencv_contrib -lopencv_core\
-lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgproc\
-lopencv_legacy -lopencv_ml -lopencv_objdetect -lopencv_ocl\
-lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_video\
-lopencv_videostab
Also, here is the .pro file for a dummy test application.
QT += core
QT -= gui
CONFIG += c++11
TARGET = apptest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += "/home/foo/mylib/" #this is where `a.h` is
LIBS += "/home/foo/mylib/build/mylib.so.1.0.0"
QMAKE_CXXFLAGS += "-Wall"
QMAKE_LFLAGS += "-Wl,-rpath-link,/usr/local/lib"
QMAKE_LFLAGS += "-Wl,--unresolved-symbols=ignore-in-shared-libs"
You can see that I am providing /usr/local/lib as the -rpath-link where OpenCV shared objects reside. I am also instructing the linker to ignore unresolved symbols from shared libraries, which is suggested in this question and documented here.
The "right way" according to many sources is not to link OpenCV (or any dependency) in application, because this causes overlinking. In apptest, when I don't link OpenCV, I get the following linker error:
undefined reference to cv::Mat::deallocate()
undefined reference to cv::fastFree(void)
collect2: error: ld returned 1 exit status
Looking at the error, my intuition is, somehow -rpath-link is not doing what it is supposed to do.
I was not able to resolve this, I decided to deliberately link OpenCV with apptest just to see what happens. What happens is awkward: it compiles and links without errors (whether I provide --unresolved-symbols=ignore-in-shared-libs option or not). But when I run the app, it crashes without any exceptions from OpenCV; cv::imread operation does not work as expected, rows and cols of image is zero.
I checked both apptest and mylib.so with readelf -d. Nothing strange occured to me,
mylib.so depends on libQt5Core and libopencv_* and it has the right SONAME entry.
apptest depends on mylib.so,libQt5Core and also libopencv_* when I did the deliberate linking.
I also tried to debug apptest with gdb. Output was not very helpful...
(gdb) r
Starting program:
/home/foo/apptest/build/apptest
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
0x00007fffffffc9b0 in ?? ()
I assume linking is not done properly, but why? How can I resolve this without having to link OpenCV libs directly in app?

Undefined reference to boost libraries in QT creator on Windows

I am trying to run a QT project on Windows that I have developed on Linux Ubuntu. Unfortunately, I cannot manage it to properly link the boost library. Here is a detailed description of the problem.
I downloaded MinGW from https://nuwen.net/mingw.html, version 13.5, such that the gcc version 5.3.0 matches the MinGW version of QT. The reason to choose this version of MinGW is that it contains the boost libraries for compression such as zlib. From the command line I compile and run my program without any problems:
g++ -std=c++11 -w -IC:/MinGW/include -LC:/MinGW/lib bAya.cpp A.o B.o C.o -o baya -lboost_iostreams -lz -lbz2
where A,B, C are my pre-compiled object files.
In QT creator I selected the MinGW compiler (C:\MinGW_53\MinGW\bin\g++.exe) and created a new default kit with the compiler.
My .pro file looks as follows:
MAKE_CXXFLAGS += -std=c++11
INCLUDEPATH += C:/MinGW_53/MinGW/include \
C:/Users/kuzk/Documents/src
LIBS += -LC:/MinGW_53/MinGW/lib/mylib \
-lboost_system \
-lboost_iostreams \
-lz \
-lbz2
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
SOURCES += main.cpp\
mainwindow.cpp \
../src/A.cpp \
../src/B.cpp \
../src/C.cpp
HEADERS += mainwindow.h \
../src/A.h \
../src/B.h \
../src/C.h
The folder C:/MinGW_53/MinGW/lib/mylib contains my .a files such as libboost_iostreams.a
When I build it, I get many undefined reference errors such as
error: undefined reference to `boost::iostreams::zlib::default_strategy'
Interestingly, if C:/MinGW_53/MinGW/lib/mylib contains also libstdc++.a I also get linking errors to std::cout, std::ifstream etc.
I am currently stuck and I will be very helpful for any feedback.
Best,
Konstantin
Adding the library path for boost_iostreams:
-LC:/MinGW/lib \
after the line:
LIBS += -LC:/MinGW_53/MinGW/lib/mylib \
should fix it.
At the end I was able to resolve the problem. Here is what I did. I am using QT 5.7 on Windows 10.
I compiled boost using QT's console as described here: http://cpp-qt-mac-win.blogspot.co.uk/2011/10/qt-boost-for-beginners-step-by-step.html
Then I created a new project and added the paths to boost and the necessary libraries, as described in my question.
An important note. I tried to update the paths in the existing project, by running qmake and then rebuilding the project. I was getting the very same errors as I was getting with the old paths to "standard" boost. Apparently, something was cached and the changes didn't do anything. However, if I give a wrong path to a library it complained. So, QT has very confusing behavior. If someone can explain it, it will be helpful.

Sha512 hash in QT via OpenSSL

I'm trying to use the Sha512 function in openSSL but can't seem to get it to work as I get compiler errors just starting into the code. I include #include <openssl/sha.h> at the top of the .cpp file, then in the action of a button event I put just the following code below.
SHA512_CTX ctx;
SHA512_Init(&ctx);
//Will uncomment below in later if I get SHA512_Init to work
//SHA512_Update(&ctx, string, strlen(string));
//SHA512_Final(digest, &ctx);
I get a linker error telling my undefined symbols for architecture x86_64, implying the function does not exist?
I'm aware QT 5 has a hash function, but I'm limited to QT 4.8 so I can not use the cryptographic sha512 hash function available in the QT 5+ framework.
Any help is appreciated!
Used macports to install openssl
I'm using Mac OS 10.9.2
MAKE FILE
#-------------------------------------------------
#
# Project created by QtCreator 2014-06-11T20:27:49
#
#-------------------------------------------------
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = ExchangeTab
TEMPLATE = app
LIBS += -L/usr/include/openssl -openssl
INCLUDEPATH += /usr/include/openssl
SOURCES += main.cpp\
mainwindow.cpp \
httpsocket.cpp \
cloaksend.cpp \
exchange.cpp
HEADERS += mainwindow.h \
httpsocket.h \
cloaksend.h \
exchange.h
FORMS += mainwindow.ui
RESOURCES += \
AppResources.qrc
Looking for cross platform solution please.
You need to link to the right library (openSSL)
Have a look here: How to Include OpenSSL in a Qt project
Specifically, add this to your .pro file.:
LIBS += -L/opt/local/lib/ -lcrypto
For including .h files add this line to your .pro file :
INCLUDEPATH += /opt/local/include
[1] says that the default include path will be /opt/local/include/.
LIBS += -L/usr/include/openssl -openssl
INCLUDEPATH += /usr/include/openssl
This looks incorrect. The OpenSSL libraries are libcrypto (-lcrypto) and libssl (-lssl). There is nolibopenssl(-lopenssl). Try:
LIBS += -L/usr/lib -lcrypto
INCLUDEPATH += /usr/include/openssl
But the libraries are version 0.9.8. You might consider upgrading to 1.0.1h.
$ ls /usr/lib | grep crypto
libcrypto.0.9.7.dylib
libcrypto.0.9.8.dylib
libcrypto.dylib
libk5crypto.dylib
And
$ /usr/bin/openssl version
OpenSSL 0.9.8y 5 Feb 2013
If you choose to upgrade, OpenSSL will install into /usr/local/ssl. Avoid mixing/matching version of OpenSSL with the following.
INCLUDEPATH += /usr/local/ssl/include/openssl
LIBS += /usr/local/ssl/lib/libcrypto.a
Its OK to specify objects and archives in LIBS. See How to add object files to a project in Qt.
Okay so I may have answered my own question but I will need some help understanding why it worked.
My make file was indeed the problem. I added the following 3 lines.
INCLUDEPATH += $$OPENSSL_INCLUDE_PATH
LIBS += $$join(OPENSSL_LIB_PATH,,-L,)
LIBS += -lcrypto
Then it magically compiled just fine. I found these in another project made with QT that compiled for OpenSSL.
Interestingly enough. I removed the top two lines so only the following remained. Then ran the clean on my project to be sure the code was being recompiled.
LIBS += -lcrypto
This also just 'worked' without linker errors. It looks like that is the only command I need. Question is... will that be cross platform friendly if I take this code and compile on linux or windows? That I am not sure, but this worked.

shared library in Qt Creator with mingw gives undefined reference error

Resolved. When I add my library as a normal internal library everything is fine. What I had failed to do was use the MY_LIBRARY_EXPORT macro on some free functions defined in a namespace. Somehow I had manipulated the library import in such a way to get those functions working, but it broke in other ways as described here.
I have not been able to use a shared library using the Qt Creator wizard. I have tried with dynamic linkage, and have failed, and cannot use as a static lib either. In both cases I get an 'undefined reference to `IMP_*' error.
Here are my pro files. They are both in the same SUB_DIR parent project and the paths are correct.
Relevant parts of the library pro file:
TARGET = Prospec
TEMPLATE = lib
CONFIG += staticlib
QMAKE_CXXFLAGS += -std=c++11
DEFINES += PROSPEC_LIBRARY
The entirety of the user .pro file. (ProspecTest is a unit test project for Prospec).
#-------------------------------------------------
#
# Project created by QtCreator 2013-12-12T15:04:30
#
#-------------------------------------------------
QT += testlib
QT -= gui
TARGET = prospectest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
QMAKE_CXXFLAGS += -std=c++11
SOURCES += prospectest.cpp \
mltest.cpp \
convertertest.cpp \
numericitemtest.cpp
DEFINES += SRCDIR=\\\"$$PWD/\\\"
HEADERS += \
utilities.h \
mltest.h \
convertertest.h \
numericitemtest.h
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../Prospec/release/ -lProspec
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../Prospec/debug/ -lProspec
INCLUDEPATH += $$PWD/../Prospec/debug
DEPENDPATH += $$PWD/../Prospec/debug
win32:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../Prospec/release/libProspec.a
else:win32:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../Prospec/debug/libProspec.a
# Boost
INCLUDEPATH += C:/boost/boost_1_55_0/
LIBS += "-LC:/boost/boost_1_55_0/stage/lib/"
EDIT: the undefined reference errors happen only where I invoke functionality in a source file. For instance, if I construct a library object I get the error, but if I move that objects constructor into a header file, then compile is OK. Right now I'm not sure if the problem is due to the Qt environment, or me not understanding shared libraries in general.
The error you describe points to a linker error. It happens when a necessary object/lib file is not specified. The most likely scenario is this: you include a header and use a function from that header, but don't specify in which library that function is defined.
Small example:
//test.c
#include <winsock.h>
int main() { gethostbyname("localhost"); }
'undefined reference' linker error:
>gcc test.c
cczICEqq.o:test.c:(.text+0x1e): undefined refer ence to `gethostbyname#4'
collect2.exe: error: ld returned 1 exit status
In this case you would have to specify libwsock32.a like this:
gcc test.c -lwsock32
Also, note that a libsomething.a is not the only place where a reference can be resolved. You might have missed an object file.
Unfortunately without more details I am not able to tell you the exact problem.
You probably forgot to export your symbols, as described here on MSDN and in various questions on this website. It's a pain in general, and there are a few ways to handle this, none much better than the other.
This makes it so that the DLL and import library actually contain a reference to the symbols you compiled into it. You can compare it partially to GCC's symbol visibility, although that only works in Linux, and GCC also supports the stuff described on MSDN for Windows.
Had the same problem just now. Build was working fine on macOS/OSX but not on Windows with the same codebase. Thanks to rubenvb, who pointed me in the right direction. Here the full solution, how to do it for Qt:
Use Q_DECL_EXPORT on functions when building the lib. And use Q_DECL_IMPORT when using the functions from the lib.
Example how to do this here: https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application#Creating_a_shared_library
Solved the problem in my case, hope it helps!