PDA

View Full Version : My application links against both qt4 and qt5 libs



jiveaxe
22nd December 2013, 17:32
Hi, I'm porting my application from qt4 to qt5. I filled my CMakeLists.txt of if/else conditions to handle qt5 (default) and qt4 (minimum) requirements. During compilation I fixed all error messages and seems all ok. But when I try to launch it, seg-fault occurs and the debugger opens disassembler on a line of /usr/lib/libQtGui.so.4, and this is strange since the application should build against qt5. I used ldd on the executable and I found a mixture of qt4/qt5 libraries:


$ ldd ./myapp
linux-vdso.so.1 (0x00007f21147ae000)
libQt5Core.so.5 => /usr/lib/libQt5Core.so.5 (0x00007f2113f2c000)
libQt5Widgets.so.5 => /usr/lib/libQt5Widgets.so.5 (0x00007f2113749000)
libQt5Network.so.5 => /usr/lib/libQt5Network.so.5 (0x00007f2113411000)
libQt5Xml.so.5 => /usr/lib/libQt5Xml.so.5 (0x00007f21131d7000)
libQt5Svg.so.5 => /usr/lib/libQt5Svg.so.5 (0x00007f2112f8b000)
libphonon.so.4 => /usr/lib/libphonon.so.4 (0x00007f2112d1b000)
libQtSvg.so.4 => /usr/lib/libQtSvg.so.4 (0x00007f2112ac5000)
libqjson.so.0 => /usr/lib/libqjson.so.0 (0x00007f211289e000)
libQtXml.so.4 => /usr/lib/libQtXml.so.4 (0x00007f211265c000)
libQt5Gui.so.5 => /usr/lib/libQt5Gui.so.5 (0x00007f211203d000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f2111d39000)
libm.so.6 => /lib/libm.so.6 (0x00007f2111a36000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f2111820000)
libc.so.6 => /lib/libc.so.6 (0x00007f2111475000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00007f2111257000)
libz.so.1 => /usr/lib/libz.so.1 (0x00007f2111042000)
libicui18n.so.51 => /usr/lib/libicui18n.so.51 (0x00007f2110c3f000)
libicuuc.so.51 => /usr/lib/libicuuc.so.51 (0x00007f21108c8000)
libdl.so.2 => /lib/libdl.so.2 (0x00007f21106c4000)
librt.so.1 => /lib/librt.so.1 (0x00007f21104bc000)
libglib-2.0.so.0 => /usr/lib/libglib-2.0.so.0 (0x00007f21101c7000)
/lib64/ld-linux-x86-64.so.2 (0x00007f2114591000)
libX11.so.6 => /usr/lib/libX11.so.6 (0x00007f210fe90000)
libssl.so.1.0.0 => /usr/lib/libssl.so.1.0.0 (0x00007f210fc26000)
libcrypto.so.1.0.0 => /usr/lib/libcrypto.so.1.0.0 (0x00007f210f81e000)
libQtCore.so.4 => /usr/lib/libQtCore.so.4 (0x00007f210f33e000)
libQtGui.so.4 => /usr/lib/libQtGui.so.4 (0x00007f210e6bd000)
libQtDBus.so.4 => /usr/lib/libQtDBus.so.4 (0x00007f210e442000)
libpulse.so.0 => /usr/lib/libpulse.so.0 (0x00007f210e1f8000)
libpulse-mainloop-glib.so.0 => /usr/lib/libpulse-mainloop-glib.so.0 (0x00007f210dff4000)
libqzeitgeist.so.1 => /usr/lib/libqzeitgeist.so.1 (0x00007f210ddd0000)
libpng16.so.16 => /usr/lib/libpng16.so.16 (0x00007f210db9c000)
libGL.so.1 => /usr/lib/libGL.so.1 (0x00007f210d86e000)
libicudata.so.51 => /usr/lib/libicudata.so.51 (0x00007f210c124000)
libpcre.so.0 => /usr/lib/libpcre.so.0 (0x00007f210becb000)
libxcb.so.1 => /usr/lib/libxcb.so.1 (0x00007f210bcae000)
libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x00007f210ba0f000)
libSM.so.6 => /usr/lib/libSM.so.6 (0x00007f210b808000)
libICE.so.6 => /usr/lib/libICE.so.6 (0x00007f210b5ed000)
libXrender.so.1 => /usr/lib/libXrender.so.1 (0x00007f210b3e3000)
libXcursor.so.1 => /usr/lib/libXcursor.so.1 (0x00007f210b1d9000)
libfontconfig.so.1 => /usr/lib/libfontconfig.so.1 (0x00007f210af9f000)
libXext.so.6 => /usr/lib/libXext.so.6 (0x00007f210ad8e000)
libdbus-1.so.3 => /usr/lib/libdbus-1.so.3 (0x00007f210ab48000)
libjson-c.so.2 => /usr/lib/libjson-c.so.2 (0x00007f210a93e000)
libpulsecommon-4.0.so => /usr/lib/pulseaudio/libpulsecommon-4.0.so (0x00007f210a6d2000)
libnvidia-tls.so.319.49 => /usr/lib/libnvidia-tls.so.319.49 (0x00007f210a4cf000)
libnvidia-glcore.so.319.49 => /usr/lib/libnvidia-glcore.so.319.49 (0x00007f2107f77000)
libXau.so.6 => /usr/lib/libXau.so.6 (0x00007f2107d74000)
libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0x00007f2107b6f000)
libbz2.so.1.0 => /usr/lib/libbz2.so.1.0 (0x00007f210795f000)
libuuid.so.1 => /usr/lib/libuuid.so.1 (0x00007f210775b000)
libXfixes.so.3 => /usr/lib/libXfixes.so.3 (0x00007f2107555000)
libexpat.so.1 => /usr/lib/libexpat.so.1 (0x00007f210732d000)
libsndfile.so.1 => /usr/lib/libsndfile.so.1 (0x00007f21070c6000)
libasyncns.so.0 => /usr/lib/libasyncns.so.0 (0x00007f2106ec1000)
libFLAC.so.8 => /usr/lib/libFLAC.so.8 (0x00007f2106c90000)
libvorbisenc.so.2 => /usr/lib/libvorbisenc.so.2 (0x00007f21067c2000)
libvorbis.so.0 => /usr/lib/libvorbis.so.0 (0x00007f2106596000)
libogg.so.0 => /usr/lib/libogg.so.0 (0x00007f2106390000)
libnsl.so.1 => /lib/libnsl.so.1 (0x00007f2106178000)
libresolv.so.2 => /lib/libresolv.so.2 (0x00007f2105f61000)

Unfortunately I can't remove qt4 since required by KDE. This is an excerpt of CMakeLists.txt I'm using:


...
cmake_minimum_required(VERSION 2.6)

set( CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules )

find_package(Qt5Core)
if( Qt5Core_DIR )
message(STATUS "Found Qt5! Be aware that Qt5-support is still experimental and not officially supported!")
ADD_DEFINITIONS(-fPIC)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Network REQUIRED)
find_package(Qt5Xml REQUIRED)
find_package(Qt5Svg REQUIRED)
find_package(Qt5LinguistTools REQUIRED)
set(CMAKE_AUTOMOC ON)
endif()
if( NOT Qt5Core_DIR )
find_package(Qt4 COMPONENTS QTCORE QTGUI QTNETWORK QTSVG QTXML)
endif()
find_package(Phonon REQUIRED)
find_package(QJson REQUIRED)

# Handle Translations
file( GLOB TRANS_FILES ${CMAKE_SOURCE_DIR}/translations/myapp_*.ts)
set(TRANSLATIONS ${TRANS_FILES})

...

if( Qt5Core_DIR )
include_directories(${Qt5Core_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS}
${Qt5Network_INCLUDE_DIRS}
${Qt5Xml_INCLUDE_DIRS}
${Qt5Svg_INCLUDE_DIRS}
${PHONON_INCLUDES}
${QJSON_INCLUDE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR})

qt5_add_resources(myapp_RC_SRCS ${myapp_RCS} )
qt5_wrap_ui(myapp_UI_HEADERS ${myapp_UI})
qt5_add_translation(myapp_I18N ${TRANSLATIONS})
endif()
if( NOT Qt5Core_DIR )
include_directories(${QT_INCLUDES}
${PHONON_INCLUDES}
${QJSON_INCLUDE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR})
qt4_add_resources(myapp_RC_SRCS ${myapp_RCS} )
qt4_wrap_ui(myapp_UI_HEADERS ${myapp_UI})
qt4_automoc(${myapp_SRCS})
qt4_add_translation(myapp_I18N ${TRANSLATIONS})
endif()

add_executable(myapp main.cpp ${myapp_SRCS} ${myapp_RC_SRCS} ${myapp_UI_HEADERS} ${myapp_I18N})

if( Qt5Core_DIR )
target_link_libraries(myapp
${Qt5Core_LIBRARIES}
${Qt5Widgets_LIBRARIES}
${Qt5Network_LIBRARIES}
${Qt5Xml_LIBRARIES}
${Qt5Svg_LIBRARIES}
${PHONON_LIBRARY}
${QT_QTSVG_LIBRARY}
${QJSON_LIBRARY}
${QT_QTXML_LIBRARY})
endif()
if( NOT Qt5Core_DIR )
target_link_libraries(myapp
${QT_QTCORE_LIBRARY}
${QT_QTGUI_LIBRARY}
${QT_QTNETWORK_LIBRARY}
${PHONON_LIBRARY}
${QT_QTSVG_LIBRARY}
${QJSON_LIBRARY}
${QT_QTXML_LIBRARY})
endif()

Any idea about the problem?

Very thanks.

ChrisW67
22nd December 2013, 19:50
I cannot see that KDE has anything to do with this: you are not linking to any KDE library in the snippet you show.
Chances are that the phonon and QJson libraries you have asked CMake to find and link have been built with Qt4. Build and link to Qt5 versions or use the Qt5 equivalents.

jiveaxe
23rd December 2013, 09:46
I cannot see that KDE has anything to do with this: you are not linking to any KDE library in the snippet you show.
My intention was to remove qt4 and leave only qt5 stuff and see if it compiled correctly.


Chances are that the phonon and QJson libraries you have asked CMake to find and link have been built with Qt4. Build and link to Qt5 versions or use the Qt5 equivalents.

This should be the real problem. I already compiled phonon4qt5. For QJson I read that Qt5 has native support for json, so no need of external library. But I'm stuck converting QVariantMap in json QByteArray (I can't find something like QJson::Serializer)...

EDIT: Never mind. Found right way

Thanks for your help