Build Qt 5 PostgreSQL Plugin for Android: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 3: Line 3:
Building postgresql plugin is pretty straight forward.
Building postgresql plugin is pretty straight forward.


If you don't want to build them yourself you can download the plugin "here":https://drive.google.com/open?id=0ByPpOAN5EsHKfmgwRTFvQUl5Z1NvUnlYMHptTEs0d2xEc24xZ19Jb0ZDMTBpb3JDQ014ZkU. All you need to do is copy libqsqlpsql.so into /path/to/qt/android_armv7/plugins/sqldrivers/. It's statically linked to libpq!
If you don't want to build them yourself you can download the plugin "here":https://drive.google.com/open?id=0ByPpOAN5EsHKfmgwRTFvQUl5Z1NvUnlYMHptTEs0d2xEc24xZ19Jb0ZDMTBpb3JDQ014ZkU. All you need to do is copy libqsqlpsql.so into /path/to/qt/android_armv7/plugins/sqldrivers/. It's statically linked to libpq!


= Setting up Enviroment Variables =
= Setting up Enviroment Variables =


Compiling only libpq should work fine with android-9 which is what qt-android is currently compiled with.<br /><code>export ANDROID_NDK_ROOT=&quot;/path/to/android/ndk&amp;quot;<br />SR=&quot;$ANDROID_NDK_ROOT/platforms/android-9/arch-arm&amp;quot;<br />BR=&quot;$ANDROID_NDK_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-&quot;</code>
Compiling only libpq should work fine with android-9 which is what qt-android is currently compiled with.<br /><code>export ANDROID_NDK_ROOT="/path/to/android/ndk"<br />SR="$ANDROID_NDK_ROOT/platforms/android-9/arch-arm"<br />BR="$ANDROID_NDK_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-"</code>


= Downloading =
= Downloading =
Line 17: Line 17:
cd into the postgresql directory and run configure
cd into the postgresql directory and run configure


<code>STRIP=&quot;$BR&amp;quot;strip RANLIB=&quot;$BR&amp;quot;ranlib OBJDUMP=&quot;$BR&amp;quot;objdump AR=&quot;$BR&amp;quot;ar CC=&quot;$BR&amp;quot;gcc CFLAGS=—sysroot=$SR CPP=&quot;$BR&amp;quot;cpp CPPFLAGS=$CFLAGS  ./configure —prefix=$SR/usr —host=arm-linux-androideabi —target=arm-linux-androideabi —build=&quot;$CHOST&amp;quot; —without-readline</code>
<code>STRIP="$BR"strip RANLIB="$BR"ranlib OBJDUMP="$BR"objdump AR="$BR"ar CC="$BR"gcc CFLAGS=—sysroot=$SR CPP="$BR"cpp CPPFLAGS=$CFLAGS  ./configure —prefix=$SR/usr —host=arm-linux-androideabi —target=arm-linux-androideabi —build="$CHOST" —without-readline</code>


Since android requires that .so files end in .so and not with a version number copy and replace two things in src/Makefile.shlib
Since android requires that .so files end in .so and not with a version number copy and replace two things in src/Makefile.shlib


&quot;lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)&quot; with &quot;lib$(NAME)$(DLSUFFIX)&quot; and &quot;lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)&quot; with &quot;lib$(NAME)$(DLSUFFIX)&quot;
"lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)" with "lib$(NAME)$(DLSUFFIX)" and "lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)" with "lib$(NAME)$(DLSUFFIX)"


<code>sed -e 's/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)/lib$(NAME)$(DLSUFFIX)/g' -i src/Makefile.shlib<br />sed -e 's/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)/lib$(NAME)$(DLSUFFIX)/g' -i src/Makefile.shlib</code>
<code>sed -e 's/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)/lib$(NAME)$(DLSUFFIX)/g' -i src/Makefile.shlib<br />sed -e 's/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)/lib$(NAME)$(DLSUFFIX)/g' -i src/Makefile.shlib</code>
Line 31: Line 31:
= Building the plugin =
= Building the plugin =


Next download the source for Qt 5 if you don't have it. We only base http://download.qt.io/archive/qt/5.4/5.4.0/submodules/qtbase-opensource-src-5.4.0.tar.xz After downloading and extracting cd into &quot;qtbase-opensource-src-5.4.0/src/plugins/sqldrivers/psql/&amp;quot;
Next download the source for Qt 5 if you don't have it. We only base http://download.qt.io/archive/qt/5.4/5.4.0/submodules/qtbase-opensource-src-5.4.0.tar.xz After downloading and extracting cd into "qtbase-opensource-src-5.4.0/src/plugins/sqldrivers/psql/"


Run qmake followed by make<br /></code>qmake &quot;INCLUDEPATH+=/path/to/postgresql-9.4.1/src/interfaces/libpq /path/to/postgresql-9.4.1/src/include&amp;quot; &quot;LIBS+=-L/path/to/postgresql-9.4.1/src/interfaces/libpq/ -lpq&amp;quot;<br />make install<code>
Run qmake followed by make<br /></code>qmake "INCLUDEPATH+=/path/to/postgresql-9.4.1/src/interfaces/libpq /path/to/postgresql-9.4.1/src/include" "LIBS+=-L/path/to/postgresql-9.4.1/src/interfaces/libpq/ -lpq"<br />make install<code>


= Build your Android App =
= Build your Android App =


Finally to build your android app you'll need to add libpq.so. Add this line to your .pro file<br /></code>ANDROID_EXTRA_LIBS=/path/to/postgresql-9.4.1/src/interfaces/libpq/libpq.so</code>
Finally to build your android app you'll need to add libpq.so. Add this line to your .pro file<br /></code>ANDROID_EXTRA_LIBS=/path/to/postgresql-9.4.1/src/interfaces/libpq/libpq.so</code>

Revision as of 06:43, 25 February 2015

h1. Overview

Building postgresql plugin is pretty straight forward.

If you don't want to build them yourself you can download the plugin "here":https://drive.google.com/open?id=0ByPpOAN5EsHKfmgwRTFvQUl5Z1NvUnlYMHptTEs0d2xEc24xZ19Jb0ZDMTBpb3JDQ014ZkU. All you need to do is copy libqsqlpsql.so into /path/to/qt/android_armv7/plugins/sqldrivers/. It's statically linked to libpq!

Setting up Enviroment Variables

Compiling only libpq should work fine with android-9 which is what qt-android is currently compiled with.

export ANDROID_NDK_ROOT="/path/to/android/ndk"<br />SR="$ANDROID_NDK_ROOT/platforms/android-9/arch-arm"<br />BR="$ANDROID_NDK_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-"

Downloading

Posgresql source can be downloaded from http://www.postgresql.org/ftp/source/ These instructions are only tested on the 9.4.1. Once downloaded extract.

Building

cd into the postgresql directory and run configure

STRIP="$BR"strip RANLIB="$BR"ranlib OBJDUMP="$BR"objdump AR="$BR"ar CC="$BR"gcc CFLAGS=sysroot=$SR CPP="$BR"cpp CPPFLAGS=$CFLAGS  ./configure prefix=$SR/usr host=arm-linux-androideabi target=arm-linux-androideabi build="$CHOST" without-readline

Since android requires that .so files end in .so and not with a version number copy and replace two things in src/Makefile.shlib

"lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)" with "lib$(NAME)$(DLSUFFIX)" and "lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)" with "lib$(NAME)$(DLSUFFIX)"

sed -e 's/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)/lib$(NAME)$(DLSUFFIX)/g' -i src/Makefile.shlib<br />sed -e 's/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)/lib$(NAME)$(DLSUFFIX)/g' -i src/Makefile.shlib

Next run make. For the driver we only need libpq.

make -C src/interfaces/libpq<code>

= Building the plugin =

Next download the source for Qt 5 if you don't have it. We only base http://download.qt.io/archive/qt/5.4/5.4.0/submodules/qtbase-opensource-src-5.4.0.tar.xz After downloading and extracting cd into "qtbase-opensource-src-5.4.0/src/plugins/sqldrivers/psql/"

Run qmake followed by make<br />

qmake "INCLUDEPATH+=/path/to/postgresql-9.4.1/src/interfaces/libpq /path/to/postgresql-9.4.1/src/include" "LIBS+=-L/path/to/postgresql-9.4.1/src/interfaces/libpq/ -lpq"
make install

= Build your Android App =

Finally to build your android app you'll need to add libpq.so. Add this line to your .pro file<br />

ANDROID_EXTRA_LIBS=/path/to/postgresql-9.4.1/src/interfaces/libpq/libpq.so