Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when compiling Ruby 1.8.7 from source: math.c:37: error: missing binary operator before token "("

This is really odd:

: josh@josh; wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7.tar.bz2
: josh@josh; tar xvjf ruby-1.8.7.tar.bz2 
: josh@josh; cd ruby-1.8.7/
: josh@josh; CFLAGS='-O0 -g -Wall' ./configure --disable-pthread
: josh@josh; make
gcc -O0 -g -Wall    -DRUBY_EXPORT -D_GNU_SOURCE=1  -I. -I.    -c array.c
[...]
gcc -O0 -g -Wall    -DRUBY_EXPORT -D_GNU_SOURCE=1  -I. -I.    -c math.c
math.c: In function ‘domain_check’:
math.c:37: error: missing binary operator before token "("
make: *** [math.o] Error 1

Sure enough, math.c cannot be compiled:

: josh@josh; gcc -O0 -g -Wall    -DRUBY_EXPORT -D_GNU_SOURCE=1  -I. -I.    -c math.c
math.c: In function ‘domain_check’:
math.c:37: error: missing binary operator before token "("

There's nothing obviously wrong with math.c:

static void
domain_check(x, msg)
    double x;
    char *msg;
{
    while(1) {
    if (errno) {
        rb_sys_fail(msg);
    }
    if (isnan(x)) {
#if defined(EDOM)
        errno = EDOM;
#elif define(ERANGE)  # <== this is line 37
        errno = ERANGE;
#endif
        continue;
    }
    break;
    }
}

Let's see what the pre-processor is generating:

: josh@josh; gcc -E -O0 -g -Wall    -DRUBY_EXPORT -D_GNU_SOURCE=1  -I. -I.    -c math.c >/tmp/math.c 
math.c:37: error: missing binary operator before token "("

OK, looks alright, so let's compile it and see where the problem is:

: josh@josh; gcc -O0 -g -Wall    -DRUBY_EXPORT -D_GNU_SOURCE=1  -I. -I.    -c /tmp/math.c
: josh@josh; echo $?
0
: josh@josh; ls -l math.o
-rw-r--r-- 1 josh josh 20904 2011-03-04 13:47 math.o

Now that I've manually compiled math.c into math.o, I can build ruby. But I'd still like to know what in the world is going on.

Any ideas?

like image 862
Josh Glover Avatar asked Mar 04 '11 12:03

Josh Glover


1 Answers

It should read #elif defined(XXX).

like image 93
Lindydancer Avatar answered Oct 15 '22 23:10

Lindydancer