All sorts of nitty-gritty technical things.

Linux – General Purpose IO (GPIO) from user space code

I came across this good article about how to program general purpose IO (GPIO) from user space code in Linux

http://falsinsoft.blogspot.ie/2012/11/access-gpio-from-linux-user-space.html

It contains a nice little synopsis of the steps involved with setting up and reading & writing inputs and outputs!

Massive 10GB Magento Database

This is a classic, a venerable magento database was presented to me today – it had grown over time to 10GB and was in danger of being booted right off its hosting due to its wide girth!  I’d say cron hadn’t been run for years.

Anyway its very easy to clean up the magento database, most of the data bloat is stored in a group of log tables and can be just delete right away by running the following queries on the DB:

truncate log_customer;
truncate log_quote;
truncate log_summary;
truncate log_summary_type;
truncate log_url;
truncate log_url_info;
truncate log_visitor;
truncate log_visitor_info;
truncate log_visitor_online;

This reduced the DB size from 10GB to about 150MB.

OpenCV Display window title corrupted and multiple windows show

I had a very strange (and annoying problem) with an OpenCV project in VS2012, when my program created an image display window (namedWindow) I noticed that its window title was all garbled and soon afterwards other display windows were created even though the code had not requested them.

I spent a lot of time comparing the VS2012 projects settings with those of another working project and eventually found that I could make the problem go away by adding this to the ‘Preprocessor Definitions’ setting:

_ITERATOR_DEBUG_LEVEL=0

I have no idea at the moment why adding this fixed the problem but it did! I must have added it to the working project (which was born inside VS2010) but I can’t remember why!

RealVNC Server, Android Viewer – Server did not offer supported security type

I had a bit of trouble getting some Android VNC viewers to connect to a Real VNC server on windows 7 today. The most common error message proffered by the viewers while trying to connect was:

Server did not offer supported security type

It seems this may be caused by Real VNC using some non-standard VNC extensions…

Anyway I found that I could get rid of the error message and get the VNC connections to work correctly by changing the following Real VNC Settings (see screen-shot below):

(a) Change ‘Authentication’ to ‘VNC Password’ (and configure a password)
(b) Change ‘Encryption’ to ‘Prefer on’

Note that the second change probably results in the connection being unencrypted so be careful if you are using this on a public network!

server did not offer supported security type

Build / Cross Compile lighttpd for ARM Linux with pcre

This is a record of how I built lighttpd with pcre for ARM. Most examples of cross compiling lighttpd for ARM do not include pcre, but to get the best out of lighttpd you really do need pcre built in. So we first need to get and cross compile pcre and then lighttpd.

Build pcre for ARM

In this example I assume that you create the build directories in you home directory, e.g. /home/youruser/ , you will need to change this in the following commands to match your actual directory set-up.

cd /home/youruser
mkdir buid_pcre
cd build_pcre

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.21.tar.gz
tar -xzf pcre-8.21.tar.gz

cd pcre-8.21

./configure --host=arm-linux-gnueabi CC=arm-linux-gnueabi-gcc \
AR=arm-linux-gnueabi-ar STRIP=arm-linux-gnueabi-strip \
RANLIB=arm-linux-gnueabi-ranlib \
--prefix=/home/youruser/build_lighttpd/build_pcre/_install

make
make install

This should build pcre and install the output files into the following directory:

/home/youruser/build_lighttpd/build_pcre/_install

Change this path to suit your own needs.

Build lighttpd for ARM

Now that we have build pcre we can build lighttpd as follows, there is a bit of trickery involved for getting it to build with pcre, but happily this article showed me the way (thanks)!

cd /home/youruser
mkdir build_lighttpd
cd build_lighttpd

wget http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.32.tar.gz

tar -zxvf lighttpd-1.4.32.tar.gz

cd lighttpd-1.4.32

./configure -prefix=/home/youruser/build_lighttpd/_install \ 
-host=arm-linux-gnueabi CC=arm-linux-gnueabi-gcc \
RANLIB=arm-linux-gnueabi-ranlib STRIP=arm-linux-gnueabi-strip\
--enable-shared --without-mysql --without-zlib --without-bzip2 \
--disable-ipv6 \
PCRECONFIG=/home/youruser/build_lighttpd/build_pcre/_install/bin/pcre-config \
PCRE_LIB=/home/youruser/build_lighttpd/build_pcre/_install/lib/libpcre.a \
CFLAGS="$CFLAGS -DHAVE_PCRE_H=1 -DHAVE_LIBPCRE=1 -I/home/youruser/build_lighttpd/build_pcre/_install/include"

make
make install

Again remember to change: /home/youruser/ in each case.

If the build succeded, all the files that you need to install lighttpd on your target ARM device should be under: /home/youruser/build_lighttpd/_install

Here is an article which talks about how to manually install lighttpd.

But at a very minimum you need to:

(a) Download and edit the config file – lighttpd.conf
(b) Copy the pcre libs to /usr/lib or similar – libpcre.so.0 , libpcre.so.0.0.1
(c) Copy on the lighttpd binary from: /home/youruser/build_lighttpd/_install/sbin
(d) Copy on the lib folder from /home/youruser/build_lighttpd/_install/lib
(e) Run lighttpd specifying the paths to config file and lib folder, for example:

lighttpd -D -f /etc/lighttpd/lighttpd.conf -m /usr/lib

Thanks to the following articles for the build info!

http://fengh2000.blogspot.ie/2009/06/how-to-cross-compile-lighttpd-with-pcre.html

http://stackoverflow.com/questions/12079498/lighttpd-refernces-wrong-lib-location

Boost link error – undefined reference to boost filesystem detail copy_file( )

I had some difficulty today getting my code to link to boost::filesystem::copy_file() (linking to boost version 1.53.0, gcc v4.7.2), I suffered from link errors like this:

undefined reference to `boost::filesystem::detail::copy_file(boost::filesystem::path const&, boost::filesystem::path const&, boost::filesystem::copy_option, boost::system::error_code*)’

From reading this post, it seemed that my problem may have stemmed from my use of c++0x.

 

None of the suggested solutions in this thread worked for me & I double checked that had built boost with -std=c++0x.

 

In the end after looking through the code in filesystem/operations.hpp the only thing that fixed my linking problem was to #define BOOST_NO_CXX11_SCOPED_ENUMS before including , like this:

#define BOOST_NO_CXX11_SCOPED_ENUMS

#include 

This may well not be the best/proper way to fix the problem but it was the only thing that worked for me..

 

Other relevant links that I found are here, here and here.

 

Building / Cross Compiling OpenCV for Linux ARM

This article outlines the steps necessary for building OpenCV for a Linux ARM target. OpenCV is an open-source, cross-platform computer vision and machine vision library.

 

I cross compiled OpenCV for a Xilinx Zinq ARM system yesterday by more-or-less following the steps outlined in the above document – I had to change a few things to get the build to work. I am documenting the exact steps that I took in case anybody is having trouble (probably future me!).

 

I started with a fairly clean Ubuntu install on a virtual machine (it already had git installed) , first I installed some build tools, feel free to skip any that you already have:

sudo apt-get install build-essential
sudo apt-get install cmake

Then I installed the GNU ARM tool-chain:

sudo apt-get install gcc-arm-linux-gnueabi
sudo apt-get install g++-arm-linux-gnueabi

This installed version 4.7 of the compilers while the build process calls for version 4.6, to get around this I modified the cmake platform file slightly, see below.

 

Create a build directory, cd into it and get the OpenCV source from github:

mkdir opencv_build
cd opencv_build
git clone https://github.com/Itseez/opencv.git
 

To fix the version problem I modified the compiler version in the platform file (this may not be the most correct way to do this but it worked for me!):

 

I edited this file:

 

./opencv/platforms/linux/arm-gnueabi.toolchain.cmake

 

I changed the GCC_COMPILER_VERSION variable’s value from 4.6 to 4.7 to match my installed compiler. I had to edit the file as I wasn’t able to override these variables from the command line.

 

Now create a sub-directory called build and cd into it:

mkdir build
cd build

And configure the build:

cmake -DSOFTFP=ON  -DCMAKE_TOOLCHAIN_FILE=../opencv/platforms/linux/arm-gnueabi.toolchain.cmake ../opencv

This should complete without errors if you have the compiler that it is looking for installed etc.

 

Now run ‘make’ and ‘make install’:

make
make install

Make will take a few minutes to run, make install should copy the output files to a subdirectory called ‘install’.

 

All being well you should now have all the include and lib files that you need to build an OpenCV app for your ARM device.

 

Cross compiling libjpeg for Linux on ARM

I am taking this opportunity to document a cross compilation procedure for libjpeg targeting ARM Linux mostly so that I won’t have to go searching for it again in the future!

First create a directory and cd to it: 

mkdir libjpeg_build
cd libjpeg_build

Now get the source and un-tar it:

wget http://www.ijg.org/files/jpegsrc.v9.tar.gz

tar -xzvf jpegsrc.v9.tar.gz

Configure the build, specifying your C compiler and cross compilation host, then make:

./configure --host=arm-xilinx-linux CC=arm-xilinx-linux-gnueabi-gcc

make

Here, I am using the xilinx build of the compiler, hence the reference to xilinx in the host and CC parameters, if I wasn’t using the xilinx tools the above configure command may have looked more like this:

./configure --host=arm-linux CC=arm-linux-gnueabi-gcc

Now make install, specifying a directory for the output:

make install DESTDIR=./_install

If all goes well the output of the build process should be written to the _install directory, copy the .so files to the appropriate directory on your target device (e.g. /usr/local/lib)

Drupal 6 – Easy Social buttons not displaying in node

If you are using the easy social module in drupal 6 with a quirky (read rubbish) theme (or sometimes ubercart) then you may notice that the social media buttons don’t get displayed on some node types.

 

To get around this problem you may have to alter the node’s template to manually insert the Easy Social module’s output – and hence the social media buttons. Add the following to the relevant node template which can be found in your theme folder:

easy_social ;?>

More information can be found here.

 

PS It’s high time you were using drupal 7! ;-)

 

Eclipse CDT – Using boost thread library with eclipse

If you are scratching your head about how to setup Eclipse and CDT to use the boost thread library then have a look at the first post in this thread:

 

http://www.eclipse.org/forums/index.php/m/787571/

 

It explains which project settings need to be changed.

 

Thanks to Robert!