Jul 20, 2009

How to cross compile Perl

Download Perl from www.perl.org and extract it into a folder
The go to that folder and type
sh ./Configure -des -Dusecrosscompile \
-Dtargethost=[ip of the target] \
-Dtargetdir=/cross/bin \
-Dtargetuser=[user to SSH to the target]
-Dtargetarch=arm-linux \
-Dcc=/opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/bin/arm-9tdmi-linux-gnu-gcc \
-Dincpth=/opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/include \
-Dusrinc=/opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/include \
And then type make to build the Perl

The other solution which is simpler is as following
Download the http://www.rootshell.be/~axs/perl/ and extract it into existing Perl source code (5.10.0)

Then configure and compile it:
./configure --target=$target --sysroot=/mnt/target
make DESTDIR=... install

Jul 15, 2009

cygwin undefined reference to `_glEnd' and related OpenGL function

Sometime, when building OpenGL application under cygwin, we fail to compile with following message or relating OpenGL function message "undefined reference to `_glEnd' and related OpenGL function"

The simple test is such as following
#include <GL/gl.h>
int main() { glEnd(); return 0; }

$ gcc -lGL test.c -o test
/.../.../ccO7Cfcr.o:test.c:(.text+0x2b): undefined reference to `_glEnd'
collect2: ld returned 1 exit status

That is because the OpenGL library on cygwin is depended on GLU library also. We need to link with GLU when linking with GL
Change the link command to $ gcc -lGL -lGLU test.c -o test and everything is OK.

I met this issue while compiling ShivaVG package on cygwin

Jul 11, 2009

How to get stack trace of a function

In Java,
try {
throw new Exception();
} catch (Exception ex) {

In C++, we'll use backtrace function as following (note: the backtrace does not exist in uClibc so that if you want to use, you must patch the library to enable it)

#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
void print_trace (void)
void *array[10];
size_t size;
char **strings;
size_t i;

size = backtrace (array, 10);

strings = backtrace_symbols (array, size);
printf ("Obtained %zd stack frames.\n", size);

for (i = 0; i < size; i++)
printf ("%s\n", strings[i]);
free (strings);

Or we can use sigsegv as followin http://www.tlug.org.za/wiki/index.php/Obtaining_a_stack_trace_in_C_upon_SIGSEGV