PDA

View Full Version : Deploying App on Linux


janus
6th May 2008, 00:17
hi,

I have written an App (Qt4.3.4, Eclipse) on Windows that uses the sqlitedriver as plugin. But I build the driver with the latest sqlite version (3.5.8). Everything works fine on Windows. My Question is what the best Option on Linux is. It seems I can not just put the driverplugin in the app/sqldrivers/ path. If their is an old version of sqlite on the system the App loads that system driver or the plugin that was build with qt-source (which is an old version as well).
Is their a way to force the App to load the plugin that comes with the App on Linux?
I am sorry, my knowledge about Linux is very limited. I learned from several websites that I could build it in static mode for Linux to avoid that. But I also would like to extend my App with own addidional plugins (using the pluginloader) to add more features. But if I build it in static mode I can nor use this approach!? Thats what i read in the documentation.
Could anyone give me an advice how to solve this dilemma.
thx in advance.

wysota
6th May 2008, 00:58
Is their a way to force the App to load the plugin that comes with the App on Linux?
You can make sure the proper version of the library is earlier than the other in the library search path by putting its directory path in the LD_LIBRARY_PATH environment variable. An alternative would be to force the linker to load the library from a predetermined path by using the "rpath" option of the compiler (google for more info).

But if I build it in static mode I can nor use this approach!? Thats what i read in the documentation.
Yes, that's correct.

janus
6th May 2008, 18:24
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[])
{
QCoreApplication a(argc, argv);

qDebug() << QSqlDatabase::drivers();

return a.exec();
}

CMakeLists.txt
The first part is from the QtCentre cmake Tutorial. The second part from www.cmake.org/Wiki (http://www.cmake.org/Wiki/CMake_RPATH_handling#No_relinking_and_full_RPATH_f or_the_install_tree)


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})

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?

wysota
6th May 2008, 21:04
Plugins have to be in well defined paths and the compilation process has nothing to do with it. Take a look at QCoreApplication::addLibraryPath() and plugins documentation as well as our FAQ section about plugins.

janus
6th May 2008, 21:25
hm, but then I dont understand your previous post, Anyway, thanx . I think I can solve this issue with qt.conf

wysota
6th May 2008, 22:18
Earlier I didn't understand what you mean but your previous post clarified the situation. At least I think so.