Qt 二进制链接到 Qt 5 和(错误地)链接到 Qt 4,当链接到 Qwt 时导致分段错误

Qt binary linked to both Qt 5 and (wrongly) to Qt 4 causing segmentation fault when linked to Qwt

我有一个 Qt / ROS / Qwt 应用程序。一切都很顺利,直到我尝试 link 到 Qwt。请注意,我使用的是 Qwt 6.1.2,它应该在 Qt 5.5 上 运行。的确,例子运行很好。

当我 运行 我的二进制文件时,即使我不使用 Qwt,它也会崩溃。我只需要 link 我的代码到 Qwt 就可以实现。而且-这是我认为的问题-,gdb 给出了以下错误:

ram received signal SIGSEGV, Segmentation fault.
0x00007ffff25eadfc in ?? () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4

这是错误的,因为二进制文件应该使用 Qt 5.5。为了让事情变得更奇怪,ldd 给出:

>> ldd dls_gui | grep 'Qt'
    libQt5Widgets.so.5 => /home/jcolmenares/Qt/5.5/gcc_64/lib/libQt5Widgets.so.5 (0x00007f684cadc000)
    libQt5Gui.so.5 => /home/jcolmenares/Qt/5.5/gcc_64/lib/libQt5Gui.so.5 (0x00007f684afad000)
    libQt5Core.so.5 => /home/jcolmenares/Qt/5.5/gcc_64/lib/libQt5Core.so.5 (0x00007f684a867000)
    libQtSvg.so.4 => /usr/lib/x86_64-linux-gnu/libQtSvg.so.4 (0x00007f684862c000)
    libQtGui.so.4 => /usr/lib/x86_64-linux-gnu/libQtGui.so.4 (0x00007f6847979000)
    libQtCore.so.4 => /usr/lib/x86_64-linux-gnu/libQtCore.so.4 (0x00007f6847493000)
    libicui18n.so.54 => /home/jcolmenares/Qt/5.5/gcc_64/lib/libicui18n.so.54 (0x00007f6844e33000)
    libicuuc.so.54 => /home/jcolmenares/Qt/5.5/gcc_64/lib/libicuuc.so.54 (0x00007f6844a85000)
    libicudata.so.54 => /home/jcolmenares/Qt/5.5/gcc_64/lib/libicudata.so.54 (0x00007f684305b000)

如何 link同时使用 Qt5 和 Qt4? Qwt 似乎被 linked 到仅 Qt 5.5:

>> ldd /usr/local/qwt-6.1.2/lib/libqwt.so | grep 'Qt'
    libQt5PrintSupport.so.5 => /home/jcolmenares/Qt/5.5/gcc_64/lib/libQt5PrintSupport.so.5 (0x00007fbcee13a000)
    libQt5Svg.so.5 => /home/jcolmenares/Qt/5.5/gcc_64/lib/libQt5Svg.so.5 (0x00007fbcedee5000)
    libQt5OpenGL.so.5 => /home/jcolmenares/Qt/5.5/gcc_64/lib/libQt5OpenGL.so.5 (0x00007fbcedc8e000)
    libQt5Widgets.so.5 => /home/jcolmenares/Qt/5.5/gcc_64/lib/libQt5Widgets.so.5 (0x00007fbced410000)
    libQt5Gui.so.5 => /home/jcolmenares/Qt/5.5/gcc_64/lib/libQt5Gui.so.5 (0x00007fbcecbfc000)
    libQt5Core.so.5 => /home/jcolmenares/Qt/5.5/gcc_64/lib/libQt5Core.so.5 (0x00007fbcec4b7000)
    libicui18n.so.54 => /home/jcolmenares/Qt/5.5/gcc_64/lib/libicui18n.so.54 (0x00007fbcea032000)
    libicuuc.so.54 => /home/jcolmenares/Qt/5.5/gcc_64/lib/libicuuc.so.54 (0x00007fbce9c84000)
    libicudata.so.54 => /home/jcolmenares/Qt/5.5/gcc_64/lib/libicudata.so.54 (0x00007fbce825a000)

我的 CMakeList.txt 文件是:

cmake_minimum_required(VERSION 2.8.11)
project(dls_gui)

# Find the QtWidgets library
find_package(Qt5Widgets)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)

# Qwt related
# list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_packages")
# find_package(Qwt REQUIRED)
find_path(QWT_INCLUDE_DIR qwt.h HINTS /usr/local/qwt-6.1.2/include)
find_library(QWT_LIBRARY qwt /usr/local/qwt-6.1.2/lib/)
include_directories(${QWT_INCLUDE_DIR})


# catkin related
catkin_package()
find_package(catkin REQUIRED COMPONENTS roscpp sensor_msgs urdf)
include_directories( ${catkin_INCLUDE_DIRS} include)

# source, header and resources files list
set(CPP_SOURCES src/main.cpp src/mainwindow.cpp src/basewidget.cpp src/rosQtNode.cpp 
    src/joints_sliders.cpp src/superslider.cpp src/support_polygon.cpp)

set(CPP_HDRS include/mainwindow.h include/basewidget.h include/rosQtNode.hpp 
    include/joints_sliders.hpp include/superslider.hpp include/support_polygon.hpp)

set(QRC_RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/dls_gui.qrc)

# Add the include directories for the Qt 5 Widgets module to# the compile lines.
include_directories(${Qt5Widgets_INCLUDE_DIRS} )

# Use the compile definitions defined in the Qt 5 Widgets module
add_definitions(${Qt5Widgets_DEFINITIONS})

# Generate headers from ui files
qt5_wrap_ui(UIS_HDRS src/mainwindow.ui)

# Generate moc files from cpp
qt5_wrap_cpp(MOC_SOURCES ${CPP_SOURCES} ${CPP_HDRS})

# Generate resources 
qt5_add_resources(RESOURCES_RCC ${RESOURCE})

# Add compiler flags for building executables (-fPIE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS} -std=c++11")

## Ros include dirs
include_directories(include ${catkin_INCLUDE_DIRS})

# Tell CMake to create the helloworld executable
add_executable(dls_gui ${CPP_SOURCES}  ${UIS_HDRS} ${MOC_SOURCES} ${QRC_RESOURCES})
add_executable(testRos src/testRos.cpp)
qt5_use_modules(dls_gui Widgets)

#Link the helloworld executable to the Qt 5 widgets library.
target_link_libraries(dls_gui ${QWT_LIBRARY} Qt5::Widgets ${catkin_LIBRARIES} )

target_link_libraries(testRos ${catkin_LIBRARIES})

我不认为这与 ROS 相关,但是,重要的是要说源代码是通过 catkin_make 等编译的

最后但同样重要的是,qmake指的是5.5版本:

>> qmake --version
QMake version 3.0
Using Qt version 5.5.0 in /home/jcolmenares/Qt/5.5/gcc_64/lib

编辑:明确一点:我希望(需要)编译所有内容并link编辑到相同的 Qt 版本。但不知何故,并没有发生。

我把一切都切换回了 Qt4。厌倦了在不应该发生的问题上浪费时间。仍然不知道二进制文件如何结束链接到两个不同版本的 Qt,仅当链接到 Qwt 时,其中 Qwt 仅链接到 Qt5,而没有链接到 Qwt 的二进制文件也仅链接到 Qt5。

您需要 link 和 qwt-qt5

qwt 是 QWT 的 Qt4 版本,它使用 libQtGui.so.4 等,您可以在上面的 ldd 输出中看到。链接 qwt-qt5 只需要 Qt5 so 个文件。