【问题标题】:Error when compiling Ruby 1.8.7 from source: math.c:37: error: missing binary operator before token "("从源代码编译 Ruby 1.8.7 时出错:math.c:37:错误:在标记“(”之前缺少二元运算符
【发布时间】:2023-03-26 23:44:01
【问题描述】:

这真的很奇怪:

: 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

果然math.c无法编译:

: 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 "("

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;
    }
}

让我们看看预处理器正在生成什么:

: 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 "("

好的,看起来还不错,我们编译一下,看看问题出在哪里:

: 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

现在我已经手动将 math.c 编译为 math.o,我可以构建 ruby​​。但我还是想知道这个世界到底发生了什么。

有什么想法吗?

【问题讨论】:

    标签: ruby gcc c-preprocessor


    【解决方案1】:

    应该是#elif defined(XXX)

    【讨论】:

    • 谢谢!哇,所以这是 Ruby 中的一个错误?!想知道为什么他们的构建测试没有抓住它?一些奇怪的CFLAGS?在 ruby​​-1.8.7-p334 中开箱即用。
    • 猜测他们的构建环境采用了#if 分支,在这种情况下,#elif 之后的任何内容都被忽略了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-13
    • 1970-01-01
    • 2019-08-29
    • 2014-02-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多