[SRILM User List] Compiling srilm with gcc 4.6.1 (and possibly any versions >= 4.3): patched Lattice sources

Edward Thomas Grefenstette egrefen at gmail.com
Wed May 16 15:49:13 PDT 2012


After further investigation, it turns out you are correct. I was also having compilation problems with apple's llvm-gcc 4.2 (on an older system), which I would not encounter if I explicitly asked to use the non-apple non-llvm-based g++-4.2 on the same system.

The fault lies with the llvm-gcc/clang  not liking the non-static definition in srlim/dstruct/src/Array.h:

#if !defined(DEBUG) && defined(__GNUC__) && (!defined(__INTEL_COMPILER) || __INTEL_COMPILER >=900)
# define makeArray(T, A, n)		T A[n]
#else
# define makeArray(T, A, n)		StaticArray<T> A(n)
#endif

The first option (T A[n]) is selected for llvm-gcc, when in fact it should be the second.

If you I replace the whole section above in Array.h with the following line

#if !defined(DEBUG) && defined(__GNUC__) && (!defined(__INTEL_COMPILER) || __INTEL_COMPILER >=900) && !defined(__llvm__)

then srlim compiles fine with llvm-gcc-4.x, without need for modification of LatticeIndex.cc and LatticeNgrams.cc, as it correctly detects llvm-gcc or clang which do not generally support variable length arrays, and defines makearray appropriately.

How do I submit a patch?

Best,
Ed

On 16 May 2012, at 19:05, Andreas Stolcke wrote:

> On 5/16/2012 9:25 AM, Edward Grefenstette wrote:
>> 
>> Dear srilm users,
>> 
>> As mentioned in another email, I've encountered and later resolved some problems building srilm with gcc v4.6. The fault, it seems, lays with the makearray declarations used in LatticeIndex.cc and LatticeNgrams.cc found in ./lattice/src/ of the srilm folder.
>> 
>> I've managed to get srilm to compile by "cheating" and using an older version of g++ passed to make with CXX flag, but ideally it'd be better to fix the source to be compliant with C++0x, as enforced by gcc versions >= 4.3 (I think).
>> 
>> I attach to this email the modified LatticeIndex.cc and LatticeNgrams.cc files from srilm 1.6.0 (diffs reproduced at the end of the email), which allowed me to compile srilm using gcc 4.6.1 without passing an older g++ using the CXX flag. Could someone please sanity check the changes? If they're good, it'd be nice to see these files updated in the main distribution so that others don't encounter this frustrating problem when they update their compilers and decide to (re)build srilm.
> SRILM compiles fine on gcc 4.5.x, which is the latest version I've verified myself.
> 
> It is possible that gcc 4.6.x changed (removed)  the support for stack-allocated arrays with size computed at run-time, to be inline with standard C++.   In that case a simple change in Array.h (the conditional definition of makeArray()) should suffice.
> 
> I will try to get my hands on gcc 4.6.x to verify this, but feel free to submit a patch along those lines.
> 
> Andreas
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.speech.sri.com/pipermail/srilm-user/attachments/20120516/936cade2/attachment.html>


More information about the SRILM-User mailing list