问题描述
我有一个Qt / ROS / Qwt应用程序。一切正常,直到我尝试链接到Qwt。请注意,我使用的是Qwt 6.1.2,应在Qt 5.5上运行。确实,这些示例运行良好。
I have a Qt / ROS / Qwt application. Everything was going fine until I tried to link to Qwt. Note that I'm using Qwt 6.1.2 which should run on Qt 5.5. Indeed, the examples run fine.
运行二进制文件时,即使我未使用Qwt,它也会崩溃。我只需要将我的代码链接到Qwt即可。并且-这是我认为的问题-,gdb给出以下错误:
When I run my binary, it crashes even if I'm not using Qwt. I just need to link the my code to Qwt for that to happen. And -here is the issue I think-, gdb gives the following error:
ram received signal SIGSEGV, Segmentation fault.
0x00007ffff25eadfc in ?? () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
错误,因为二进制文件应使用Qt 5.5。为了使事情变得更怪异,ldd给出:
Which is wrong since the binary should be using Qt 5.5. To make things more weird, ldd gives:
>> 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)
如何链接到Qt5和Qt4? Qwt似乎只链接到Qt 5.5:
How can I be linked to both Qt5 and Qt4? Qwt seems to be linked to only 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文件是:
My CMakeList.txt file is:
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等编译的。
I don't think this is ROS related, nevertheless, is important to say that the source code is compiled via catkin_make etc.
最后但并非最不重要的一点,qmake指的是5.5版:
Last but not least, qmake refers to version 5.5:
>> qmake --version
QMake version 3.0
Using Qt version 5.5.0 in /home/jcolmenares/Qt/5.5/gcc_64/lib
编辑:只是要清楚:我想要(需要)编译并链接到同一Qtversión的所有内容。但是不知何故,这没有发生。
Just to be clear: I want (need) everything compiled and linked to the same Qt versión. But somehow, is not happening.
推荐答案
我将所有内容都切换回了Qt4。厌倦了在不应该发生的问题上浪费时间。仍然不知道二进制文件如何链接到Qt的两个不同版本,仅当链接到Qwt时,Qwt仅链接到Qt5,而没有链接到Qwt的二进制文件也只链接到Qt5。
I switched everything back to Qt4. Got tired of wasting time on an issue that should not happen. Still have no idea how the binary ended linked to two different versions of Qt, only when linked to Qwt, where Qwt was linked only to Qt5 and the binary without the linkage to Qwt was also only linked to Qt5.
这篇关于链接到Qt 5和(错误地)链接到Qt 4的Qt二进制文件,链接到Qwt时导致分段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!