I tried so solve the problem by using cmake. I made a little example:
main.cpp
#include <QtCore>
#include <QCoreApplication>
#include <QDebug>
#include <QSqlDatabase>
int main(int argc, char *argv[])
{
return a.exec();
}
#include <QtCore>
#include <QCoreApplication>
#include <QDebug>
#include <QSqlDatabase>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug() << QSqlDatabase::drivers();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
CMakeLists.txt
The first part is from the QtCentre cmake Tutorial. The second part from www.cmake.org/Wiki
PROJECT( SQLITE_RPATH )
# with SET() command you can change variables or define new ones
# here we define SAMPLE_SRCS variable that contains a list of all .cpp files
# note that we don't need \ at the end of line
SET( SQLITE_RPATH_SRCS
./main.cpp )
# enable warnings
ADD_DEFINITIONS( -Wall )
# by default only QtCore and QtGui modules are enabled
# other modules must be enabled like this:
SET( QT_USE_QTSQL TRUE )
# this command finds Qt4 libraries and sets all required variables
# note that it's Qt4, not QT4 or qt4
FIND_PACKAGE( Qt4 REQUIRED )
# add some useful macros and variables
# (QT_USE_FILE is a variable defined by FIND_PACKAGE( Qt4 ) that contains a path to CMake script)
INCLUDE( ${QT_USE_FILE} )
# and finally this will run moc:
QT4_WRAP_CPP( SQLITE_RPATH_MOC_SRCS ${SQLITE_RPATH_MOC_HDRS} )
# we need this to be able to include headers produced by uic in our code
# (CMAKE_BINARY_DIR holds a path to the build directory, while INCLUDE_DIRECTORIES() works just like INCLUDEPATH from qmake)
INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR} )
# here we instruct CMake to build "sample" executable from all of the source files
ADD_EXECUTABLE( SQLITE_RPATH ${SQLITE_RPATH_SRCS} ${SQLITE_RPATH_MOC_SRCS} )
# last thing we have to do is to tell CMake what libraries our executable needs,
# luckily FIND_PACKAGE prepared QT_LIBRARIES variable for us:
TARGET_LINK_LIBRARIES( SQLITE_RPATH ${QT_LIBRARIES} )
#-------------------------------------------------------------------------------
# skip the full RPATH for the build tree
SET(CMAKE_SKIP_BUILD_RPATH TRUE)
# when building, use the install RPATH already
# (so it doesn't need to relink when installing)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
# the RPATH to be used when installing
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
#--------------------------------------------------------------------------------
MESSAGE(STATUS "CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH}")
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/SQLITE_RPATH
DESTINATION ${CMAKE_INSTALL_PREFIX})
PROJECT( SQLITE_RPATH )
# with SET() command you can change variables or define new ones
# here we define SAMPLE_SRCS variable that contains a list of all .cpp files
# note that we don't need \ at the end of line
SET( SQLITE_RPATH_SRCS
./main.cpp )
# enable warnings
ADD_DEFINITIONS( -Wall )
# by default only QtCore and QtGui modules are enabled
# other modules must be enabled like this:
SET( QT_USE_QTSQL TRUE )
# this command finds Qt4 libraries and sets all required variables
# note that it's Qt4, not QT4 or qt4
FIND_PACKAGE( Qt4 REQUIRED )
# add some useful macros and variables
# (QT_USE_FILE is a variable defined by FIND_PACKAGE( Qt4 ) that contains a path to CMake script)
INCLUDE( ${QT_USE_FILE} )
# and finally this will run moc:
QT4_WRAP_CPP( SQLITE_RPATH_MOC_SRCS ${SQLITE_RPATH_MOC_HDRS} )
# we need this to be able to include headers produced by uic in our code
# (CMAKE_BINARY_DIR holds a path to the build directory, while INCLUDE_DIRECTORIES() works just like INCLUDEPATH from qmake)
INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR} )
# here we instruct CMake to build "sample" executable from all of the source files
ADD_EXECUTABLE( SQLITE_RPATH ${SQLITE_RPATH_SRCS} ${SQLITE_RPATH_MOC_SRCS} )
# last thing we have to do is to tell CMake what libraries our executable needs,
# luckily FIND_PACKAGE prepared QT_LIBRARIES variable for us:
TARGET_LINK_LIBRARIES( SQLITE_RPATH ${QT_LIBRARIES} )
#-------------------------------------------------------------------------------
# skip the full RPATH for the build tree
SET(CMAKE_SKIP_BUILD_RPATH TRUE)
# when building, use the install RPATH already
# (so it doesn't need to relink when installing)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
# the RPATH to be used when installing
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
#--------------------------------------------------------------------------------
MESSAGE(STATUS "CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH}")
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/SQLITE_RPATH
DESTINATION ${CMAKE_INSTALL_PREFIX})
To copy to clipboard, switch view to plain text mode
The executable is installed in usr/local and the driver is in /usr/local/lib .
But the executable does not find the driver in /usr/local/lib . If their is one, it loads the driver from the Qt Path ... any idea?
Bookmarks