Maple 11 Compiler:-Compile() GNU GCC version awful BUG

The issue

When trying to compile a routine using the Compiler: module inside Maple version 11.0 on a Suse Linux 32 bit box, an awful error message showed up:

> p := proc( x :: float ) :: float; 2.3 * x end proc:
> Compiler:-Compile(p);
Error, (in Compiler:-Compile) possible installation problem: GNU C compiler (gcc) not found in your command search path (PATH). You will need to
restart Maple after ensuring that gcc is installed and adjusting your PATH environment variable.

Curiously, this odd behaviour dissapeared completely if trying to do so on the same computer but this time running Maple version 13.0.

Trying to determine the GNU GCC version

Maple is  written mostly in java. And, to make things worse, it is a binary and you don’t own its sources. Doing some research across the website  I found some tricks I tried to follow. Thank God I could understand a bit more concerning how Maple used the Compiler module facility. Thus, I learned I could call Compiler:-Tools(); or even Compiler:-Build(); to interact, so so, with Maple and GCC from within. This way, I ran Compiler:-Build(); and that’s what came out:

> Compiler:-Build();
local indentOptions, buildVarDB, buildvars, compileCommand, compileCommand2, linkCommand, linkCommand2, owversion;
export DumpConfiguration, AutoConfigure, testConfiguration, IndentGeneratedCode, BuildContext, PrintContext, CompileSourceFile, LinkDSO,
OpenWatcomDir, OpenWatcomMapleDir, GetBuildVariable, SetBuildVariable, AddLibrary, ResetBuildVariables, CompilerPlatform, CompilerSystem,
ssystem, setup, populate_buildvars, FindCompiler;
option load = setup;
description “tools for compiling external C code generated by the numeric code translator”;

So, I decided to have a look at its configuration. The routine DumpConfiguration() seemed quite suitable. Right after running it, I found out the GNU GCC version was reported as “FAIL”. Obviously, the GNU gcc was installed on the computer, and it was doing its job quite well for such a long time. Besides, it worked as smooth as silk when calling Compiler:-Compile() from Maple 13. So, I tried the Compiler:-Tools():

> Compiler:-Tools();
local pathGCC, winShortPath, resetCounters, approved_super_type, paramCount, localCount;
export gccversion, gccversion_patterns, keys, newParam, newLocal, getRememberTable, getReturnType, getReturnSuperType, getParamTypes,
getParamSuperTypes, checkArrayParamTypes, checkModifiedEnvVars, doBasicCompilabilityChecks, getTempDir, RemoveDirectory, `recursive?`,
dirname, makedirpath, setup, fixPath, fullPath, pathCat;
option load = setup;
description “miscellaneous tools for the Compiler module”;

It was plain to me the culprit had to be the routine gccversion, but having the array gccversion_patterns, I guessed the GNU gcc reported version when running gcc –version was bad-processed or parsed. So, I ran gccversion directly and then I had a look at the gccversion_patterns array:

> Compiler:-Tools:-gccversion();

> Compiler:-Tools:-gccversion_patterns();
[[“gcc (GCC) %d.%d.%d.%d”(), 4], [“gcc-%d.%d.%d.%d”(), 4], [“gcc (GCC) %d.%d.%d”(), 3], [“gcc-%d.%d.%d”(), 3], [“gcc (GCC) %d.%d”(), 2],

[“gcc-%d.%d”(), 2], [“egcs-%d.%d.%d.%d”(), 4], [“egcs-%d.%d.%d”(), 3], [“egcs-%d.%d”(), 2], [“powerpc-apple-darwin8-gcc-%d.%d.%d.%d”(), 4],

[“powerpc-apple-darwin8-gcc-%d.%d.%d”(), 3], [“powerpc-apple-darwin8-gcc-%d.%d”(), 2], [“i686-apple-darwin8-gcc-%d.%d.%d.%d”(), 4],

[“i686-apple-darwin8-gcc-%d.%d.%d”(), 3], [“i686-apple-darwin8-gcc-%d.%d”(), 2]]

There it was. Running gcc –version on that system returned:

/usr/bin/gcc –version
gcc (SUSE Linux) 4.3.1 20080507 (prerelease) [gcc-4_3-branch revision 135036]
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO

Clearly, gccversion_patterns missed this pattern! When it came to Maple 13, that was quite solved:

[“gcc (GCC) %d.%d.%d.%d”(), 4],
[“gcc-%d.%d.%d.%d”(), 4],
[“gcc (GCC) %d.%d.%d”(), 3],
[“gcc-%d.%d.%d”(), 3],
[“gcc (GCC) %d.%d”(), 2],
[“gcc-%d.%d”(), 2],
[“egcs-%d.%d.%d.%d”(), 4],
[“egcs-%d.%d.%d”(), 3], [“egcs-%d.%d”(), 2],
[“powerpc-apple-darwin8-gcc-%d.%d.%d.%d”(), 4],
[“powerpc-apple-darwin8-gcc-%d.%d.%d”(), 3],
[“powerpc-apple-darwin8-gcc-%d.%d”(), 2],
[“powerpc-apple-darwin9-gcc-%d.%d.%d.%d”(), 4],
[“powerpc-apple-darwin9-gcc-%d.%d.%d”(), 3],
[“powerpc-apple-darwin9-gcc-%d.%d”(), 2],
[“i686-apple-darwin8-gcc-%d.%d.%d.%d”(), 4],
[“i686-apple-darwin8-gcc-%d.%d.%d”(), 3],
[“i686-apple-darwin8-gcc-%d.%d”(), 2],
[“i686-apple-darwin9-gcc-%d.%d.%d.%d”(), 4],
[“i686-apple-darwin9-gcc-%d.%d.%d”(), 3],
[“i686-apple-darwin9-gcc-%d.%d”(), 2],
[“gcc version %d.%d.%d”(), 3],
[“gcc version %d.%d”(), 2],
[“gcc version %d”(), 1]]


I could not alter the Maple behaviour – it is a binary and I do not own its sources -. Instead, I created a “fake gcc” bash shell script, fixing the “–version” flag and its returned pattern to Maple this way:

if [ $# -eq 0 ]; then
	case "$1" in
		# Patch cadena maple 11:
       		         echo "gcc (GCC) 4.3.1"
       	        	 #echo "gcc version 4.3.2 (Debian 4.3.2-1.1)"
		# Executar el gcc real:
			/usr/bin/gcc $*
exit $?

I ensured this was the first gcc run, simply by altering the PATH session variable. Shortly after that, I tried to compile some Maple code:

> p := proc( x :: float ) :: float; 2.3 * x end proc:
> Compiler:-Compile(p);
call_external, define_external(_m253ac5a8cc5036d6afc59b34b8f52b8e, MAPLE, LIB = “/var/tmp/root-12338/”);
call_external(0, -1207454416, true, args)
end proc

> p(3.5);

So far so good.