Discussion:
[Libpqxx-general] Cross Compiling libpqxx
mokon
2013-01-26 04:07:10 UTC
Permalink
Hello,

I trust this is the correct place to ask a question such as this. If
it is not and if you could direct me to the correct place that would
be great.

Ok, so a little background. I need to cross compile libpqxx but I am
running into a little trouble. First, I have my cross compiler and my
crosstool-ng directory which is where I am installing everything.

CROSS="arm-rpi-linux-gnueabi"

PREFIX="/home/xxx/repository/platform/cross/prefix/arm-rpi-linux-gnueabi/"

I have previously successfully cross compiled and installed libpq as
can be seen in the portion of a script below:

postgresql)
echo "Building PostgreSQL Libary"

cd deps
if [ ! -d "postgresql" ]; then
git://git.postgresql.org/git/postgresql.git
fi

cd postgresql
./configure --host=${CROSS} --prefix=${PREFIX} --without-readline
--without-zlib
make
make install
cd ../..
;;

The problem comes when I attempt to cross compile the libpqxx library.
Here is the portion of a script that does that:

pqxx)
echo "Building PostgreSQL libpqxx Libary"

cd deps
if [ ! -d "libpqxx" ]; then
svn co svn://pqxx.org/libpqxx/trunk/ libpqxx
fi

cd libpqxx
./configure --host=${CROSS} --prefix=${PREFIX} # --with-sysroot=${PREFIX}
make
make install
cd ../..
;;

I am failing in configure. Here is part of the error message I am getting:

checking /usr/include/libpq-fe.h usability... yes
checking /usr/include/libpq-fe.h presence... yes
checking for /usr/include/libpq-fe.h... yes
checking for ability to compile source files using libpq... yes
checking for main in -lpq... no
configure: error:
Could not link to libpq. Make sure you have the PostgreSQL client library
installed, and that the library binary can be found in the
location returned by
"pg_config --libdir".

So as you can see a few problems are occuring here. This pg_config is
my build servers installation of postgresql so of course its including
/usr/include when I need it to be including from my ${PREFIX}
directory. Similarly we get and error is pg_config --libdir since its
not using the tool chain correctly.

Am I doing something simple wrong? What is the correct way to cross
compile this? I might be able to hack it with my own script,
pg_config, that gives the correct tool chain location but I would like
to do it the correct way...

Thanks,
David
Jeroen Vermeulen
2013-01-28 09:35:03 UTC
Permalink
I trust this is the correct place to ask a question such as this. If it
is not and if you could direct me to the correct place that would be great.
Welcome. Yes, this is the right place.
checking for ability to compile source files using libpq... yes
checking for main in -lpq... no
Could not link to libpq. Make sure you have the PostgreSQL client library
installed, and that the library binary can be found in the location
returned by
"pg_config --libdir".
So as you can see a few problems are occuring here. This pg_config is my
build servers installation of postgresql so of course its including
/usr/include when I need it to be including from my ${PREFIX} directory.
Similarly we get and error is pg_config --libdir since its not using the
tool chain correctly.
The precise build error for that test will be in config.log. You'll
probably have to scroll up a few pages; there's a lot of noise. It's
probably just picking up your native libpq instead of your
cross-compiling one. But it may help.

I haven't done any cross-compiling, so there's not much I can add. If
you're getting the wrong pg_config, try putting it somewhere that's very
early in your $PATH. It's just a shell script IIRC, so you may be able
to run it even if it's the ARM version.

That script in turn might want to run ARM binaries. If nothing else
works, I believe it's possible to set up qemu so that it will run ARM
binaries as if they were native.


Jeroen
Bryan Henderson
2013-01-29 02:37:33 UTC
Permalink
In cross compiling, you run programs specifically built to run in the build
environment (which consists of a lot of things in addition to the instruction
set), so I'm sure there's no issue with something wanting to run an ARM
binary on a non-ARM computer.

Because of the heavy bias toward compiling _for_ the same system you're
compiling _on_, the 'pg_config' for the build system is typically in the
default PATH, so you get errors like this if you don't explicitly set PATH
properly. There should be a place that the ARM version of development
component of Postgresql (header files, link libraries, etc) is installed on
the build system, and that should include a 'bin' directory that contains
'pg_config', and the build process should add that bin directory to the front
of PATH.

I don't know if there is a convention for taking care of this in the
build system distributed with something like libpqxx, but I always just do it
separately before invoking 'configure'.

'pg_config' as generated by the regular Postgresql installer is a binary, but
it does a very simple job. On _my_ cross-compiling system, I just wrote a
tiny Perl program that prints the required things for the few options that its
users actually use, and I build libpqxx just fine.

(Incidentally, any *-config program generated by an installer program is
really just a suggestion -- it's contents are really the system
administrator's responsibility).
its including /usr/include when I need it to be including from my ${PREFIX}
directory.
If you say so. Normally, people say ${PREFIX} to mean the place that they
will install the result, and while I can imagine that might be the same place
that you would get the build tools from, it seems to me it would be
problematic to mix the two.
--
Bryan Henderson San Jose, California
Loading...