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

时间:2018-12-05 15:58:00

标签: c++ linker g++ qt5 cross-compiling

我有一个带有旧libstdc ++的ARM平台。我正在从其他平台交叉编译应用程序,并且我想使用C ++语言的更高级功能,因此我要静态链接我的libstdc ++。我正在使用柯南作为软件包管理器以及许多其他动态库,并且一切运行顺利。

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

可执行文件上的'objdump -TC'表明,许多libstdc ++函数现在已导入(动态链接)而不是静态链接。

示例:

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

请注意版本“ Qt_5”。

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

当我尝试使用gp链接器之前手动解析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 

谢谢您的回答。

1 个答案:

答案 0 :(得分:0)

我找到了解决我问题的方法。我需要在lib列表的顶部显式列出标准库的静态版本。这距离理想的解决方案还很遥远,但是现在垃圾箱已按我的预期构建。

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