Sunday, March 23, 2008

yywrap it up

This weekend I decided to download the beta version of the highly anticipated Ubuntu 8.04.

After installing it on a virtual machine I promptly proceeded to building ZeroBUGS on it.

And I ran into a small roadblock: The debugger has a built-in C/C++ interpreter, for evaluating simple expressions and function calls. This code failed to link, because in this new Hardy Heron version of Ubuntu the yyFlexLexer class (see /usr/include/FlexLexer.h) has a virtual method called yywrap(). In older versions of flex yywrap used to be a standalone, extern "C" function.

To work around this issue in a portable manner I defined a new function in my configure.ac file.

It attempts to compile a small C++ program that assigns a pointer to method. If the compilation fails, I assume that yyFlexLexer::yywrap is not defined.

Here's the code:

AC_DEFUN([AC_YYFLEXLEXER_YYWRAP],
[AC_CACHE_CHECK([for yyFlexLexer::yywrap],
[ac_cv_yyFlexLexer_yywrap],
[ac_cv_yyFlexLexer_yywrap=false
cat > tmp.cpp << ---end---

#include <FlexLexer.h>
int main()
{
int (yyFlexLexer::*method)() = &yyFlexLexer::yywrap;
return 0;
}
---end---
if g++ tmp.cpp 2>/dev/null; then
ac_cv_yyFlexLexer_yywrap=true
rm a.out
fi
rm tmp.cpp])

if test "$ac_cv_yyFlexLexer_yywrap" = true; then
AC_DEFINE([HAVE_YYFLEXLEXER_YYWRAP], [1],
[Define if yyFlexLexer::yywrap is declared])
fi
])


AC_YYFLEXLEXER_YYWRAP


And you can test drive a pre-release of ZeroBUGS for Ubuntu 8.04 here: http://zero-bugs.com/8001/releases/zero_1.12-heron-032308_i386.deb

The md5sum is: 5b80e9f0f867b858620c740096e432dd

3 comments:

Unknown said...

Hi, thank for your work.
I've a little problem installin your .deb:
the result of typing

$ sudo dpkg -i --force-all zero....

is this:

Detecting plugins...
debugger_init: libpython2.5.so.1.0: cannot open shared object file: No such file or directory

I checked, and I have libpython2.5.so.1.0 installed in \usr\lib

Thanks!!
Andrea

NB: OS is UBUNTU 8.04 64bit and I need your solution to install OpenFOAM (?), see:
http://openfoam.cfd-online.com/forum/messages/1/7503.html?1209479660

Cristache said...

You do not need my DEB to install OpenFOAM. Maybe I confused you by posting that deb...

The intent of the post was to present a problem that I run into ***while working on my very own ZeroBUGS project***.

But maybe I misread and you indeed want to give my debugger a try :)

Here's the problem: the 32-bit package is not designed to install on a 64-bit system.

Please go to http://www.zero-bugs.com/8001/beta.html, and make sure you get the 64-bit version. Cheers!

Cristache said...

I believe the solution could be rewritten more elegantly by using the AC_TRY_COMPILE macro...