使用 Qt5 为 ARM 交叉编译时的静态 libstdc++

Static libstdc++ when cross-compiling for ARM while using Qt5

我有一个带有旧 libstdc++ 的 ARM 平台。我正在从其他平台交叉编译应用程序,我想使用 C++ 语言的更多高级功能,所以我静态链接了我的 libstdc++。我正在使用 Conan 作为包管理器和许多其他动态库,一切都很顺利 运行。

当我尝试添加应用程序的全新组件时出现问题,该组件是用 Qt5 编写的。 stringstream 突然停止工作 - 应用程序没有崩溃,但是 operator<<(int) 重置了流中的好位。

可执行文件上的

'objdump -TC' 显示现在导入了很多 libstdc++ 函数(动态链接)而不是静态链接。

示例:

0000000000000000      DF *UND*  0000000000000000  Qt_5        std::ostream::operator<<(int)

注意版本"Qt_5"。

我还反汇编了我的可执行文件,发现所有对 std::ostream::operator<<(int) 的调用确实是在调用导入的符号。

当我尝试在使用

的 g++ 链接器之前手动解析 libstdc++ 符号时
/usr/bin/aarch64-linux-gnu-ld -r -o out.o main.cpp.o /usr/lib/gcc-cross/aarch64-linux-gnu/7/libstdc++.a

它按预期工作,可执行文件中不再有任何与 ostream 相关的导入符号,stringstream 工作。

关于我的情况有什么想法吗?

下面是CLion执行的链接命令。使用此组合,应用程序无法运行。

/usr/bin/aarch64-linux-gnu-g++-7  -fPIC -static-libstdc++ -Wall -Wextra -pedantic -Weffc++ -Wshadow -Wstrict-aliasing -Woverloaded-virtual -Wdelete-non-virtual-dtor -Wno-unused-function -Wno-missing-braces  -g -rdynamic  -L/enviro/rv-linux/lib-target -L/enviro/rv-linux/targetfs/lib/aarch64-linux-gnu -Wl,-rpath,$ORIGIN/lib -Wl,-rpath,/enviro/rv-linux/lib-target  CMakeFiles/wwrk_core.dir/src/main.cpp.o  -o bin/wwrk_core -Wl,-rpath,/usr/local/ukita-1.2/targets/aarch64-Linux/lib:/usr/local/cuda/targets/aarch64-linux/lib:/usr/local/cuda/targets/aarch64-linux/lib/stubs:/home/wwrk/.conan/data/mosquitto/1.4.15/bincrafters/stable/package/239078edbc0e8a96a9afdcfb7771317f2343a587/lib:/home/wwrk/.conan/data/OpenSSL/1.0.2o/conan/stable/package/7dd5184ee7a9467ffac8b88942d33774d1b75240/lib:/home/wwrk/.conan/data/Qt/5.11.2/bincrafters/stable/package/07bff7c90a07530ee2d9520bd150b7df4c4bcfd4/lib:/home/wwrk/.conan/data/Qt/5.11.2/bincrafters/stable/package/e7c3abf447189e454cc0dd043a04a91b61a54baf/lib:/usr/local/ukita/samples/3rdparty/linux-aarch64/special_Xlibs/lib: lib/libAnd_driver.a lib/libAndCore-dw.a /home/wwrk/.conan/data/OpenCV/3.4.0/wwrkauto/stable/package/2a79b1e5f5284318af316f0a3dad26795379cec1/lib/libopencv_dnn.a /home/wwrk/.conan/data/OpenCV/3.4.0/wwrkauto/stable/package/2a79b1e5f5284318af316f0a3dad26795379cec1/lib/libopencv_ml.a /home/wwrk/.conan/data/OpenCV/3.4.0/wwrkauto/stable/package/2a79b1e5f5284318af316f0a3dad26795379cec1/lib/libopencv_objdetect.a /home/wwrk/.conan/data/OpenCV/3.4.0/wwrkauto/stable/package/2a79b1e5f5284318af316f0a3dad26795379cec1/lib/libopencv_shape.a /home/wwrk/.conan/data/OpenCV/3.4.0/wwrkauto/stable/package/2a79b1e5f5284318af316f0a3dad26795379cec1/lib/libopencv_stitching.a /home/wwrk/.conan/data/OpenCV/3.4.0/wwrkauto/stable/package/2a79b1e5f5284318af316f0a3dad26795379cec1/lib/libopencv_superres.a /home/wwrk/.conan/data/OpenCV/3.4.0/wwrkauto/stable/package/2a79b1e5f5284318af316f0a3dad26795379cec1/lib/libopencv_videostab.a /home/wwrk/.conan/data/OpenCV/3.4.0/wwrkauto/stable/package/2a79b1e5f5284318af316f0a3dad26795379cec1/share/OpenCV/3rdparty/lib/liblibprotobuf.a /home/wwrk/.conan/data/OpenCV/3.4.0/wwrkauto/stable/package/2a79b1e5f5284318af316f0a3dad26795379cec1/lib/libopencv_calib3d.a /home/wwrk/.conan/data/OpenCV/3.4.0/wwrkauto/stable/package/2a79b1e5f5284318af316f0a3dad26795379cec1/lib/libopencv_features2d.a /home/wwrk/.conan/data/OpenCV/3.4.0/wwrkauto/stable/package/2a79b1e5f5284318af316f0a3dad26795379cec1/lib/libopencv_flann.a /home/wwrk/.conan/data/OpenCV/3.4.0/wwrkauto/stable/package/2a79b1e5f5284318af316f0a3dad26795379cec1/lib/libopencv_highgui.a -lgthread-2.0 /home/wwrk/.conan/data/OpenCV/3.4.0/wwrkauto/stable/package/2a79b1e5f5284318af316f0a3dad26795379cec1/lib/libopencv_photo.a /home/wwrk/.conan/data/OpenCV/3.4.0/wwrkauto/stable/package/2a79b1e5f5284318af316f0a3dad26795379cec1/lib/libopencv_video.a /home/wwrk/.conan/data/OpenCV/3.4.0/wwrkauto/stable/package/2a79b1e5f5284318af316f0a3dad26795379cec1/lib/libopencv_videoio.a /home/wwrk/.conan/data/OpenCV/3.4.0/wwrkauto/stable/package/2a79b1e5f5284318af316f0a3dad26795379cec1/lib/libopencv_imgcodecs.a /home/wwrk/.conan/data/OpenCV/3.4.0/wwrkauto/stable/package/2a79b1e5f5284318af316f0a3dad26795379cec1/share/OpenCV/3rdparty/lib/libIlmImf.a /home/wwrk/.conan/data/OpenCV/3.4.0/wwrkauto/stable/package/2a79b1e5f5284318af316f0a3dad26795379cec1/lib/libopencv_imgproc.a /home/wwrk/.conan/data/OpenCV/3.4.0/wwrkauto/stable/package/2a79b1e5f5284318af316f0a3dad26795379cec1/lib/libopencv_core.a -lgstbase-1.0 -lgstreamer-1.0 -lgobject-2.0 -lglib-2.0 -lgstvideo-1.0 -lgstapp-1.0 -lgstriff-1.0 -lgstpbutils-1.0 /home/wwrk/.conan/data/jasper/2.0.14/conan/stable/package/06e35b3c6107222c50e1c22eae68c58d483cba15/lib/libjasper.a /home/wwrk/.conan/data/libjpeg/9b/bincrafters/stable/package/e6d649ca4bea46777eed92a123bea4d2c1892ea8/lib/libjpeg.a /home/wwrk/.conan/data/libpng/1.6.34/bincrafters/stable/package/42e51281839943ca78313263055e6869dd2d2f9a/lib/libpng16.a /home/wwrk/.conan/data/libwebp/0.6.1/bincrafters/stable/package/b85d569a3b57b77ebc11d00bbbe398c7753b32be/lib/libwebpdemux.a /home/wwrk/.conan/data/libwebp/0.6.1/bincrafters/stable/package/b85d569a3b57b77ebc11d00bbbe398c7753b32be/lib/libwebp.a /home/wwrk/.conan/data/libwebp/0.6.1/bincrafters/stable/package/b85d569a3b57b77ebc11d00bbbe398c7753b32be/lib/libwebpdecoder.a -lusb-1.0 -ludev /usr/local/ukita-1.2/targets/aarch64-Linux/lib/libukita.so /usr/local/cuda/targets/aarch64-linux/lib/libcudart.so /enviro/rv-linux/targetfs/usr/lib/aarch64-linux-gnu/libgstsdp-1.0.so /enviro/rv-linux/targetfs/usr/lib/aarch64-linux-gnu/libgstvideo-1.0.so /enviro/rv-linux/targetfs/usr/lib/aarch64-linux-gnu/libgstapp-1.0.so /enviro/rv-linux/targetfs/usr/lib/aarch64-linux-gnu/libgstbase-1.0.so /enviro/rv-linux/targetfs/usr/lib/aarch64-linux-gnu/libgstnet-1.0.so /enviro/rv-linux/targetfs/usr/lib/aarch64-linux-gnu/libgstreamer-1.0.so /enviro/rv-linux/targetfs/usr/lib/aarch64-linux-gnu/libgio-2.0.so /enviro/rv-linux/targetfs/usr/lib/aarch64-linux-gnu/libgobject-2.0.so /enviro/rv-linux/targetfs/usr/lib/aarch64-linux-gnu/libglib-2.0.so /usr/local/cuda/targets/aarch64-linux/lib/stubs/libcublas.so -lstdc++fs -lcuda lib/libAndCore-core.a -lpthread -lrt /home/wwrk/.conan/data/mosquitto/1.4.15/bincrafters/stable/package/239078edbc0e8a96a9afdcfb7771317f2343a587/lib/libmosquitto.so /home/wwrk/.conan/data/mosquitto/1.4.15/bincrafters/stable/package/239078edbc0e8a96a9afdcfb7771317f2343a587/lib/libmosquittopp.so -ldl /home/wwrk/.conan/data/OpenSSL/1.0.2o/conan/stable/package/7dd5184ee7a9467ffac8b88942d33774d1b75240/lib/libssl.so /home/wwrk/.conan/data/OpenSSL/1.0.2o/conan/stable/package/7dd5184ee7a9467ffac8b88942d33774d1b75240/lib/libcrypto.so /home/wwrk/.conan/data/zlib/1.2.11/conan/stable/package/8fd38d381db52e2495321ce060b9f457656f6c8f/lib/libz.a /home/wwrk/.conan/data/c-ares/1.14.0/conan/stable/package/8fd38d381db52e2495321ce060b9f457656f6c8f/lib/libcares.a -lm /home/wwrk/.conan/data/yaml-cpp/0.6.2/bincrafters/stable/package/08f0f6b54224d0f59c7a23bfbaa25f463db315ae/lib/libyaml-cpp.a -latomic lib/libAndautoDashboard.a /home/wwrk/.conan/data/Qt/5.11.2/bincrafters/stable/package/e7c3abf447189e454cc0dd043a04a91b61a54baf/lib/libQt5Location.so.5.11.2 /home/wwrk/.conan/data/Qt/5.11.2/bincrafters/stable/package/e7c3abf447189e454cc0dd043a04a91b61a54baf/lib/libQt5PositioningQuick.so.5.11.2 /home/wwrk/.conan/data/Qt/5.11.2/bincrafters/stable/package/e7c3abf447189e454cc0dd043a04a91b61a54baf/lib/libQt5Positioning.so.5.11.2 /home/wwrk/.conan/data/Qt/5.11.2/bincrafters/stable/package/e7c3abf447189e454cc0dd043a04a91b61a54baf/lib/libQt53DQuick.so.5.11.2 /home/wwrk/.conan/data/Qt/5.11.2/bincrafters/stable/package/e7c3abf447189e454cc0dd043a04a91b61a54baf/lib/libQt5Quick.so.5.11.2 /home/wwrk/.conan/data/Qt/5.11.2/bincrafters/stable/package/e7c3abf447189e454cc0dd043a04a91b61a54baf/lib/libQt5Qml.so.5.11.2 /home/wwrk/.conan/data/Qt/5.11.2/bincrafters/stable/package/e7c3abf447189e454cc0dd043a04a91b61a54baf/lib/libQt53DExtras.so.5.11.2 /home/wwrk/.conan/data/Qt/5.11.2/bincrafters/stable/package/e7c3abf447189e454cc0dd043a04a91b61a54baf/lib/libQt53DInput.so.5.11.2 /home/wwrk/.conan/data/Qt/5.11.2/bincrafters/stable/package/e7c3abf447189e454cc0dd043a04a91b61a54baf/lib/libQt5Gamepad.so.5.11.2 /home/wwrk/.conan/data/Qt/5.11.2/bincrafters/stable/package/e7c3abf447189e454cc0dd043a04a91b61a54baf/lib/libQt53DLogic.so.5.11.2 /home/wwrk/.conan/data/Qt/5.11.2/bincrafters/stable/package/e7c3abf447189e454cc0dd043a04a91b61a54baf/lib/libQt53DAnimation.so.5.11.2 /home/wwrk/.conan/data/Qt/5.11.2/bincrafters/stable/package/e7c3abf447189e454cc0dd043a04a91b61a54baf/lib/libQt53DRender.so.5.11.2 /home/wwrk/.conan/data/Qt/5.11.2/bincrafters/stable/package/e7c3abf447189e454cc0dd043a04a91b61a54baf/lib/libQt53DCore.so.5.11.2 /home/wwrk/.conan/data/Qt/5.11.2/bincrafters/stable/package/07bff7c90a07530ee2d9520bd150b7df4c4bcfd4/lib/libQt5Network.so.5.11.2 /home/wwrk/.conan/data/Qt/5.11.2/bincrafters/stable/package/e7c3abf447189e454cc0dd043a04a91b61a54baf/lib/libQt5Widgets.so.5.11.2 /home/wwrk/.conan/data/Qt/5.11.2/bincrafters/stable/package/e7c3abf447189e454cc0dd043a04a91b61a54baf/lib/libQt5Gui.so.5.11.2 /home/wwrk/.conan/data/Qt/5.11.2/bincrafters/stable/package/07bff7c90a07530ee2d9520bd150b7df4c4bcfd4/lib/libQt5Core.so.5.11.2 -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic -lX11 /home/wwrk/workdir/GST/libs/glfw/libglfw3.a -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic -lX11 /home/wwrk/workdir/GST/libs/glfw/libglfw3.a /usr/local/ukita/samples/3rdparty/linux-aarch64/special_Xlibs/lib/libXcursor.so /usr/local/ukita/samples/3rdparty/linux-aarch64/special_Xlibs/lib/libXi.so /usr/local/ukita/samples/3rdparty/linux-aarch64/special_Xlibs/lib/libXrandr.so /usr/local/ukita/samples/3rdparty/linux-aarch64/special_Xlibs/lib/libXinerama.so /enviro/rv-linux/lib-target/libGLESv2.so.2 /enviro/rv-linux/targetfs/usr/lib/aarch64-linux-gnu/libdl.so -lEGL -lGLU 

感谢您的回答。

我找到了解决问题的方法。我需要在库列表的顶部明确列出标准库的静态版本。这离理想的解决方案还有很远的距离,但现在垃圾箱按照我的预期建造了。

if(${CMAKE_CXX_COMPILER} MATCHES ".*aarch64.*")
LIST(APPEND SAMPLE_LIBRARIES
     /usr/lib/gcc-cross/aarch64-linux-gnu/7/libstdc++.a
)
endif()
...
#other libraries here