rime / librime

Rime Input Method Engine, the core library
https://rime.im
BSD 3-Clause "New" or "Revised" License
3.45k stars 562 forks source link

script_translator.cc无法编译 #462

Closed hjonline closed 3 years ago

hjonline commented 3 years ago

librime-1.7.2.tar.gz

[ 62%] Building CXX object src/CMakeFiles/rime.dir/rime/gear/script_translator.cc.o /home/xxxx/temp/rime-builds/librime-1.7.2/src/rime/gear/script_translator.cc: 在成员函数‘void rime::ScriptTranslation::PrepareCandidate()’中: /home/xxxx/temp/rime-builds/librime-1.7.2/src/rime/gear/script_translator.cc:490:23: 错误:‘exp’在此作用域中尚未声明 490 | cand->set_quality(exp(entry->weight) + | ^~~ /home/xxxx/temp/rime-builds/librime-1.7.2/src/rime/gear/script_translator.cc:504:23: 错误:‘exp’在此作用域中尚未声明 504 | cand->set_quality(exp(entry->weight) + | ^~~ make[2]: [src/CMakeFiles/rime.dir/build.make:1238:src/CMakeFiles/rime.dir/rime/gear/script_translator.cc.o] 错误 1 make[1]: [CMakeFiles/Makefile2:233:src/CMakeFiles/rime.dir/all] 错误 2 make: *** [Makefile:146:all] 错误 2

搜索了之后发现似乎和编译时的条件 -lm 有关,但不知如何处理。

lotem commented 3 years ago

怎樣重現這個編譯錯誤?

HanatoK commented 3 years ago

The issue can be fixed by adding #include <cmath> in src/rime/gear/table_translator.cc and src/rime/gear/script_translator.cc. I notice the same FTBFS issue after openSUSE tumbleweed upgraded boost from 1.75 to 1.76. Maybe the previous version of boost pulled the cmath header occasionally, but the new version does not. I am not sure, though. My rime is broken and so that fcitx5-rime, so I have to type in English. Sorry for the inconvenience. Update: 找fcitx自带的拼音输入法救急了,我也不知道怎么确定是不是boost版本的问题。

lotem commented 3 years ago

謝謝。 可能是以前通過其他第三方庫隱含地引用了該頭文件。

jwakely commented 3 years ago

This fix looks wrong. You are including <cmath> and then calling exp unqualified, with no using std::exp; or using namespace std;. You should either include <math.h> or use std::exp.

HanatoK commented 3 years ago

This fix looks wrong. You are including <cmath> and then calling exp unqualified, with no using std::exp; or using namespace std;. You should either include <math.h> or use std::exp.

@jwakely You are right. I tested the fix on GCC with libstdc++ and the code compiled, but this behavior, however, is not reliable since the standard library can choose to declare exp in the global namespace or not (see https://stackoverflow.com/a/11086087), although most implementations do. Perhaps you can make a PR to fix this issue.

jwakely commented 3 years ago

Perhaps you can make a PR to fix this issue.

OK, will do.