Cross compilation GLIBCXX version link error - qt

I'm configuring a project for a raspberry and i'm facing a linking error that i don't understand.
Context:
Actually, i cross-compiled Qt and everything worked fines.
Now, i'm trying to get opencv working as well to make image-processing in my Qt application.
Instead of cross compiling opencv, I installed it with apt install and synchronized my target sysroot in ~/raspi/sysroot.
To get raspi camera control, I'm using mmal libraries (located on rpi in /opt/vc/lib).
I cross compiled Qt with gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf so qmake is using it as well.
Raspi is running Raspian buster Lite which use a quite old glibc (the reason of using gcc-linaro-7.4.1, recommended in Qt mkspec documentation)
Problem:
When I try to compile a simple main.cpp, linker fail when linking opencv libraries:
~/raspi/sysroot/usr/lib/arm-linux-gnueabihf/libopenmpt.so.0: undefined reference to `std::random_device::_M_getentropy() const#GLIBCXX_3.4.25'
On my raspy, glibc version is
$ strings /usr/lib/arm-linux-gnueabihf/libstdc++.so.6 | grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_3.4.22
GLIBCXX_3.4.23
GLIBCXX_3.4.24
GLIBCXX_3.4.25
GLIBCXX_DEBUG_MESSAGE_LENGTH
Question:
I don't understand How opengl can't make reference to a symbol that it is installed on my raspi for my rapsi?
I tryed to compile this code on the raspi and everything link correctly.
What am i missing?
Annex:
the comand failing
~/Documents/personal/gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ -mfloat-abi=hard --sysroot=~/raspi/sysroot -Wl,-O1 -Wl,-rpath,/usr/local/qt5pi/lib -Wl,-rpath-link,~/raspi/qt5pi/lib -Wl,-rpath-link,~/raspi/sysroot/usr/lib/arm-linux-gnueabihf -Wl,-rpath-link,~/raspi/sysroot/lib/arm-linux-gnueabihf -o photomata main.o -L~/raspi/sysroot/opt/vc/lib/ -lopencv_core -lopencv_videoio -lopencv_highgui -lraspicam -lmmal -lmmal_core -lmmal_util -lmmal_vc_client -lmmal_components -lvchiq_arm -lvcsm -lcontainers -lvcos -lbcm_host ~/raspi/qt5pi/lib/libQt5MultimediaWidgets.so ~/raspi/qt5pi/lib/libQt5Widgets.so ~/raspi/qt5pi/lib/libQt5Multimedia.so ~/raspi/qt5pi/lib/libQt5Gui.so ~/raspi/qt5pi/lib/libQt5Network.so ~/raspi/qt5pi/lib/libQt5Core.so -L~/raspi/sysroot/usr/lib/arm-linux-gnueabihf -lGLESv2 -lpthread
..................
Thank you for taking the time to read and perhaps help me.
Problem continue at Missing crt1.o/crti.o for cross compilation

On my raspy, glibc version is
Your question has nothing to do with GLIBC. It's about libstdcxx.
I don't understand How opengl can't make reference to a symbol that it is installed
What's installed on your target system doesn't matter. What matters is which libraries you are linking against on your host.
From the GCC ABI table, you can tell that GLIBCXX_3.4.25 is first defined in GCC-8.0.0, and that (or later) is the version of GCC that was used to build libopenmpt.so.0.
However, you are trying to link this library with gcc-7.4.1, and against libstdc++.so.6 that came with it. Since that libstdc++.so.6 doesn't define the needed symbol, your link fails.
You need to either rebuild libopenmpt from source using your 7.4.1 compiler, or upgrade to your compiler to gcc-8.0.0 (or above).
P.S. strings is the wrong way to go about figuring out which versions are defined in a library. Use readelf -V instead.

So compiler version is in cause, there are two options:
Recompile opencv with gcc-linaro-7.4.1
Use a >8.0.0 compiler
i've create a new issue at:
Missing crt1.o/crti.o for cross compilation

Related

How to build clang compiler-rt on Windows linked against dynamic Visual C++ runtimes?

I want to use clang-cl with address sanitizers on Windows. When trying with the prebuilt llvm/clang packages from the official installers, I get linker errors because my application needs linking to the dynamic CRT (/MD) instead of the static CRT (/MT, the packages in the llvm/clang installers have compiler-rt built with this).
I want to use this with Qt, because I did not manage to build Qt itself with /MT .
According to these slides from a google engineer, building compiler-rt/asan with /MT is possible.
What do I have to change compared to these instructions when building llvm/clang in order to build compiler-rt with /MT ?
It turns out that my linker errors had another reason.
To find the required libraries, build a small hello-world app with the following command, inspect the resulting linker command and link to the required libraries explicitly:
clang-cl -v -fsanitize=address /MD test.cpp
PR35343 (currently unresolved) is about supporting automatic linking of sanitizer libs in lld-link, like it is done on other platforms.

Libm relocation error when building Qt 5 for Nitrogen6x

I am trying to build Qt 5 on a Nitrogen6x board powered by an *i.MX6Q`.
I've installed Debian/wheezy on the board and am using an Ubuntu 12.10 machine for cross-compiling.
Configuring Qt works like a charm but I am stuck in the make step.
This is the configure script I run:
./configure -v -opensource -confirm-license -reduce-relocations -no-pch -no-xcb -no-opengl -opengl es2 -qt-libpng -qt-zlib -qt-xkbcommon -qt-xcb -qt-pcre -qt-libjpeg -qt-sql-mysql -optimized-qmake\
-make libs -device imx6 \
-compile-examples \
-device-option CROSS_COMPILE=/home/finn/gcc-linaro-arm-linux-gnueabihf-4.8-2013.10_linux/bin/arm-linux-gnueabi- \
-sysroot /media/finn/d72e3b65-b529-4e5c-9d30-872e1b0c9973 \
-prefix /opt/qt5
And this is the error I receive about 5 minutes into the make process:
/home/finn/gcc-linaro-arm-linux-gnueabihf-4.8-2013.10_linux/bin/../lib/gcc/arm-linux-gnueabihf/4.8.2/../../../../arm-linux-gnueabihf/bin/ld:
/media/finn/d72e3b65-b529-4e5c-9d30-872e1b0c9973/usr/lib/libm.a(mpa.o): relocation R_ARM_THM_MOVW_ABS_NC against `a local symbol' can not be used when making a shared object; recompile with -fPIC
/media/finn/d72e3b65-b529-4e5c-9d30-872e1b0c9973/usr/lib/libm.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
I've run into the same error before, when it was trying to access libz.a but adding the qt-zlib parameter to the configure command fixed that issue.
Many articles state that affected applications/libraries should be recompiled, however I don't think that's possible as libm is part of libc6.
I already tried reinstalling it using aptitude remove libc6-dev zlib1g-dev g++-4.6
and apt-get install gcc g++ make flex bison openssl libssl-dev perl perl-base perl-modules libperl-dev build-essential
Sadly this did not fix the problem.
Debian has been installed using the official network installer as well as a Kernel and an Overlay provided by Boundarydevices, the manufacturer of the board.
Does anyone has an idea how to fix this?
My next step would be to install a completely new Debian system but I would really like to avoid that.
Edit
Compiling qtbase with -static option works for me, however I am running into this error when trying to build qtdeclarative during the make step:
/home/finn/gcc-linaro-arm-linux-gnueabihf-4.8-2013.10_linux/bin/../lib/gcc/arm-linux-gnueabihf/4.8.2/../../../../arm-linux-gnueabihf/bin/ld: cannot find crt1.o: No such file or directory
/home/finn/gcc-linaro-arm-linux-gnueabihf-4.8-2013.10_linux/bin/../lib/gcc/arm-linux-gnueabihf/4.8.2/../../../../arm-linux-gnueabihf/bin/ld: cannot find crti.o: No such file or directory
/home/finn/qt/qtbase/lib/libQt5Core.a(qlibrary_unix.o): In function `QLibraryPrivate::load_sys()':
qlibrary_unix.cpp:(.text+0xaac): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/finn/gcc-linaro-arm-linux-gnueabihf-4.8-2013.10_linux/bin/../lib/gcc/arm-linux-gnueabihf/4.8.2/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lqxcb
/home/finn/gcc-linaro-arm-linux-gnueabihf-4.8-2013.10_linux/bin/../lib/gcc/arm-linux-gnueabihf/4.8.2/../../../../arm-linux-gnueabihf/bin/ld: cannot find /lib/arm-linux-gnueabihf/libpthread.so.0
/home/finn/gcc-linaro-arm-linux-gnueabihf-4.8-2013.10_linux/bin/../lib/gcc/arm-linux-gnueabihf/4.8.2/../../../../arm-linux-gnueabihf/bin/ld: cannot find /usr/lib/arm-linux-gnueabihf/libpthread_nonshared.a
collect2: error: ld returned 1 exit status
Edit 2 - Solution
I fixed the problem and successfully compiled Qt.
All I needed to do was reinstall Ubuntu. It sure isn't an elegant solution but it works for me.
A litte late, but I found the problem/solution:
The problem is the sysroot. Normally gcc links to shared libraries. But when it cant find it, gcc uses the static libraries (.a). When you look in [sysroot]/usr/lib/arm-linux-gnueabihf the shared libraries are not in this place. There are only symlinks to /lib/arm-linux-gnueabihf. So gcc looks for the shared libraries on you host-pc, where it can not find them.
Solution
Create just the right symlink. (Here's an example for libglib, the X is the version number)
ln -s [sysroot]/lib/arm-linux-gnueabihf/libglib.so.X \
[sysroot]/usr/lib/arm-linux-gnueabihf/libglib.so
(Dont forget to remove the old symlink and create it after compiling successfully; i just do the following before compiling:
mv file.so file.so.backup
another solution
Another solution is to change the absolut symlinks to relative ones.
For Example, if your library is /lib/arm-linux-gnueabihf/libglib.so.X and you need a link in /usr/lib/arm-linux-gnueabihf/, you just do:
ln -s ../../../lib/arm-linux-gnueabihf/libglib.so.X \
[sysroot]/usr/lib/arm-linux-gnueabihf/libglib.so
libm.a(mpa.o): relocation R_ARM_THM_MOVW_ABS_NC against `a local symbol' can not be used when making a shared object
Translation: you are trying to link non--fPIC compiled object file (mpa.o from libm.a) into a shared library. You can't do that.
You need to either find/install libm.so for your target, or configure qt5 to not build shared library (possibly with --disable-shared option).

FindQt4 in CMake not recognize flag -m32

I try to build x86 application on x86_64 platform (Fedora16). In this application I'm using Qt and build system is cmake.
In CMakeLists.txt I'm using:
find_package(Qt4 REQUIRED qtmain QtCore QtGui QtWebKit)
include(${QT_USE_FILE})
cmake command for generate Makefile like this:
cmake -DCMAKE_CXX_FLAGS="-fpermissive -m32"
-DCMAKE_CXX_LINKER_PREFERENCE="-m32"
-DCMAKE_EXE_LINKER_FLAGS="-m32"
-DCMAKE_SHARED_LINKER_FLAGS="-m32"
So, after compiling linker cannot find compatible Qt library. Error like this:
/usr/bin/ld: skipping incompatible /usr/lib64/libQtWebKit.so when searching for -lQtWebKit
It's ok. In /usr/lib64 library has x64 platform. Desired library in /usr/lib, and they exist! But I don't understand, why FindQt4 not recognize platform? This script set following variable: QT_LIBRARY_DIR, QT_LIBRARIES and so one. Such variables set to following:
-- QT_LIBRARY_DIR: /usr/lib64
-- QT_LIBRARIES: optimized;/usr/lib64/libQtWebKit.so;debug;/usr/lib64/libQtWebKit_debug.so;optimized;/usr/lib64/libQtXmlPatterns.so;debug;/usr/lib64/libQtXmlPatterns_debug.so;optimized;/usr/lib64/libQtGui.so;debug;/usr/lib64/libQtGui_debug.so;optimized;/usr/lib64/libQtNetwork.so;debug;/usr/lib64/libQtNetwork_debug.so;optimized;/usr/lib64/libQtCore.so;debug;/usr/lib64/libQtCore_debug.so
My question: why not /usr/lib? and how can i fix it?
Probably because FindQt4 module knows nothing about -m32 flag.
Try to set QT_LIBRARY_DIR explicitly.

compiling musescore for uCLinux with QT and cmake

I've try few things but I still have this error when trying to cmake for blackfin:
CMake Error at CMakeLists.txt:116 (message):
Fatal error: QT (version >= 4.5.0) required. Cmake tries to detect QT4 by
searching for 'qmake' in your PATH.If you have QT4 installed, make sure
qmake is found in your PATH. If you compiled QT4 yourself make sure your
new qmake ist found _first_ in your PATH.
I'm trying to compile the source of musescore 0.9.5 to keep it compatible with the existing version of QT in uClinux options
What I did is to compile the uClinux kernel with QT lib so I can have the suitable embedded QT.
then I modified the Makefile of musescore to build with uclinux compilers. I've try different things so I show here the latest trial:
bfin:
mkdir build;
mkdir install; \
cd build;
cmake -DCMAKE_TOOLCHAIN_FILE=bfin.cmake -DCMAKE_VERBOSE_MAKEFILE=TRUE -\
DQT_QMAKE_EXECUTABLE=/home/william/Development_new/Music_Recognition/code/uCLin\
ux/rev2011R1/uclinux-dist/lib/qt-embedded/build-qt-embedded-linux-opensource-sr\
c-4.5.1/bin -libdir=/home/william/Development_new/Music_Recognition/cod\
e/uCLinux/rev2011R1/uclinux-dist/lib/qt-embedded/build-qt-embedded-linux-openso\
urce-src-4.5.1/lib \
-DCMAKE_INSTALL_PREFIX="${PREFIX}" \
mscore;
in the CMakeLists.txt I did add:
link_directories(/home/william/Development_new/Music_Recognition/code/uCLinux/r\
ev2011R1/uclinux-dist/lib/qt-embedded/build-qt-embedded-linux-opensource-src-4.\
5.1/bin)
SET(CMAKE_MODULE_PATH /home/william/Development_new/Music_Recognition/code/uCLi\
nux/rev2011R1/uclinux-dist/lib/qt-embedded/build-qt-embedded-linux-opensource-s\
rc-4.5.1/bin)
SET(CMAKE_PREFIX_PATH /home/william/Development_new/Music_Recognition/code/uCLi\
nux/rev2011R1/uclinux-dist/lib/qt-embedded/build-qt-embedded-linux-opensource-s\
rc-4.5.1/bin)
SET(QT_QMAKE_EXECUTABLE /home/william/Development_new/Music_Recognition/code/uC\
Linux/rev2011R1/uclinux-dist/lib/qt-embedded/build-qt-embedded-linux-opensource\
-src-4.5.1/bin)
my bfin.cmake look like that:
# this one is important
SET(CMAKE_SYSTEM_NAME Linux)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)
#
SET (BFIN "/opt/uClinux/bfin-uclinux")
# specify the cross compiler
SET(CMAKE_C_COMPILER ${BFIN}/bin/bfin-uclinux-gcc)
SET(CMAKE_CXX_COMPILER ${BFIN}/bin/bfin-uclinux-g++)
SET(CMAKE_LINKER ${BFIN}/bin/bfin-uclinux-ld)
#/opt/uClinux/bfin-uclinux/bfin-uclinux/runtime/usr/lib
LINK_DIRECTORIES("${BFIN}/usr/lib")
SET(CMAKE_FIND_ROOT_PATH
/opt/uClinux/bfin-uclinux/bfin-uclinux
/opt/uClinux/bfin-linux-uclibc
/opt/uClinux/bfin-linux-uclibc/bfin-linux-uclibc/runtime)
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
Thanks in advance for the help,
William
You need to put qmake in your $PATH. If you prefer to use QT_QMAKE_EXECUTABLE it has to point to the actual qmake binary and not the directory.
That being said, MuseScore 0.9.5 is a very very old version of MuseScore, the current version is 1.1 and 1.2 is coming soon. Check http://musescore.org for more information about MuseScore and don't hesitate to contact the developers on #musescore on freenode.net or on the developer mailing list at http://musescore.org/mailing-list

Linking Matlab shared library into Qt (Windows)

I want to use Matlab's C API within QT (http://www.mathworks.com/help/techdoc/matlab_external/f39876.html#bsfvqhp-1) under Windows for opening a .mat file. In my .pro file I have included
INCLUDEPATH += "C:\Program Files\MATLAB\R2010b\extern\include"
which works fine (the code compiles). But when trying to link the libmat.lib file (I have read the .dll files cannot be linked directly) using
LIBS += -L"C:\Program Files\MATLAB\R2010b\extern\lib\win32\microsoft" -llibmat
the application crashes on execution. The error given says [file].exe exited with code -1073741515
I'm neither a QT nor a Windows expert but for this project I am forced to use both (I guess it would be easier to fix this in GNU/Linux) so any help would be appreciated. Using Windows XP, QT version 4.7.0 with Qt Creator 2.0.1, and Matlab R2010b.
The last output from the compiler just in case it is useful:
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug/MainUI.exe debug/main.o debug/maingui.o debug/matparser.o debug/matutils.o debug/moc_maingui.o -L'c:/Qt/2010.05/qt/lib' -lmingw32 -lqtmaind "-LC:\Program Files\MATLAB\R2010b\extern\lib\win32\microsoft" -llibmat -lQtGuid4 -lQtCored4
I just tested building a simple C program that uses the MAT-File Interface Library with no problems. The example file is located in: matlabroot/examples/eng_mat/matcreat.c. I am compiling using MinGW on a Windows XP 32-bit machine. Here is the Makefile I used:
# root directory of MATLAB installation
MATLABROOT="/c/Program Files/MATLAB/R2010b"
.PHONY : all clean run
all: matcreat
matcreat:
gcc ${MATLABROOT}/extern/examples/eng_mat/matcreat.c -o matcreat \
-I${MATLABROOT}/extern/include \
-L${MATLABROOT}/extern/lib/win32/microsoft -llibmat -llibmx
clean:
rm -rf matcreat *.exe *.mat
run:
# UNIX uses LD_LIBRARY_PATH to find libs at runtime, Windows/MinGW uses PATH
#PATH=${MATLABROOT}/bin/win32:"${PATH}" ./matcreat
I suspect that the Matlab library will have been compiled with MSVC and since you say you are compiling your own code with MingW I would imagine the two are incompatible.
Have a look at the MingW page on mixing compilers for more information.

Resources