I have got a Qt project which I am configuring and building using CMake. When I just type “make” to build the app, it creates an app in my build directory and all works fine. However, when I type “make install” to install into a release directory, the resulting executable won’t run because it can’t find shared libraries. I get an error saying:
release/testapp: error while loading shared libraries: libQtGui.so.4: cannot open shared object file: No such file or directory
What is “make install” doing to the executable? I thought it would just copy the file it must be doing something to the file. I am trying to execute both files from the same terminal so my environment is the same.
Here is the output from ldd on the executable in the release directory (generated from “make install”):
libQtGui.so.4 => not found
libQtCore.so.4 => not found
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00906000)
libm.so.6 => /lib/tls/libm.so.6 (0x00695000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x008fa000)
libc.so.6 => /lib/tls/libc.so.6 (0x00567000)
/lib/ld-linux.so.2 (0x00548000)
Whereas if I run ldd on the executable in the build directory (created from “make”) it outputs the following:
libQtGui.so.4 => /usr/local/Trolltech/Qt-4.7.3/lib/libQtGui.so.4 (0x00560000)
libQtCore.so.4 => /usr/local/Trolltech/Qt-4.7.3/lib/libQtCore.so.4 (0x00111000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x003ec000)
libm.so.6 => /lib/tls/libm.so.6 (0x004b7000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x004da000)
libc.so.6 => /lib/tls/libc.so.6 (0x033fe000)
libpthread.so.0 => /lib/tls/libpthread.so.0 (0x004e4000)
libgthread-2.0.so.0 => /usr/lib/libgthread-2.0.so.0 (0x004f6000)
libglib-2.0.so.0 => /usr/lib/libglib-2.0.so.0 (0x02e76000)
libpng12.so.0 => /usr/lib/libpng12.so.0 (0x004fa000)
libz.so.1 => /usr/lib/libz.so.1 (0x0051e000)
libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x02df6000)
libSM.so.6 => /usr/X11R6/lib/libSM.so.6 (0x0052e000)
libICE.so.6 => /usr/X11R6/lib/libICE.so.6 (0x022ac000)
libXrender.so.1 => /usr/X11R6/lib/libXrender.so.1 (0x00537000)
libfontconfig.so.1 => /usr/lib/libfontconfig.so.1 (0x02442000)
libXext.so.6 => /usr/X11R6/lib/libXext.so.6 (0x0218a000)
libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0x03937000)
libdl.so.2 => /lib/libdl.so.2 (0x0053f000)
librt.so.1 => /lib/tls/librt.so.1 (0x02238000)
/lib/ld-linux.so.2 (0x00548000)
libexpat.so.0 => /usr/lib/libexpat.so.0 (0x02377000)
Here is the CMakeLists.txt file used to create these files:
# CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(testapp)
set(CMAKE_VERBOSE_MAKEFILE OFF)
find_package(Qt4 REQUIRED)
set (CMAKE_C_FLAGS "-m32 -g")
set (CMAKE_CXX_FLAGS "-m32 -g")
set (CMAKE_INSTALL_PREFIX release)
set(PROGNAME testapp)
add_definitions(-Wall)
set(testapp_SRCS
main.cpp
testapp.cpp
)
set(testapp_MOC_HDRS
testapp.h
)
set(QT_USE_QTGUI TRUE)
include(${QT_USE_FILE})
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
qt4_wrap_cpp(testapp_MOC_SRCS ${testapp_MOC_HDRS})
add_executable(${PROGNAME}
${testapp_SRCS}
${testapp_MOC_SRCS}
)
target_link_libraries(${PROGNAME}
${QT_LIBRARIES}
)
install(TARGETS ${PROGNAME} DESTINATION .)
It’s probably just something silly but why does the executable from “make” work but “make install” give an error? The files are both the same size.
Thanks
As you have noticed, the CMake
make installcommand strips off non-standard build paths to ensure the executable will use the system libraries and work on any system it is deployed on.You need to either install Qt into the standard library folders, or add the folder into the system library paths.
To do the latter, create a file
qt4.7.confin/etc/ld.so.conf.dwith a single line of/usr/local/Trolltech/Qt-4.7.3/lib. Then runldconfigto build the library cache. Runlddagain to check this has worked.