Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

script_translator.cc无法编译 #462

Closed
hjonline opened this issue Apr 30, 2021 · 6 comments
Closed

script_translator.cc无法编译 #462

hjonline opened this issue Apr 30, 2021 · 6 comments

Comments

@hjonline
Copy link

hjonline commented Apr 30, 2021

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
Copy link
Member

lotem commented May 1, 2021

怎樣重現這個編譯錯誤?

HanatoK added a commit to HanatoK/librime that referenced this issue May 1, 2021
Previous boost library (1.75) may implicitly include cmath, but the
latest version (1.76) does not, so the calls to exp are undefined. This
commit include cmath in script_translator.cc and table_translator.cc to
fix the issue (rime#462).
@HanatoK HanatoK mentioned this issue May 1, 2021
@HanatoK
Copy link
Contributor

HanatoK commented May 1, 2021

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 pushed a commit that referenced this issue May 1, 2021
Previous boost library (1.75) may implicitly include cmath, but the
latest version (1.76) does not, so the calls to exp are undefined. This
commit include cmath in script_translator.cc and table_translator.cc to
fix the issue (#462).
@lotem
Copy link
Member

lotem commented May 1, 2021

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

@lotem lotem closed this as completed May 1, 2021
@jwakely
Copy link

jwakely commented Aug 9, 2021

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
Copy link
Contributor

HanatoK commented Aug 10, 2021

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
Copy link

jwakely commented Aug 10, 2021

Perhaps you can make a PR to fix this issue.

OK, will do.

jwakely added a commit to jwakely/librime that referenced this issue Aug 10, 2021
As noted in rime#462, including <cmath> only guarantees that std::exp is
declared, so calling exp(double) unqualified is not portable. This adds
a using-declaration for std::exp so that unqualified calls are
guaranteed to work.
lotem added a commit that referenced this issue Jan 15, 2022
As noted in #462, including <cmath> only guarantees that std::exp is
declared, so calling exp(double) unqualified is not portable.

Squashed commit with a style change to the original PR:

commit 8b9d48c0340f3fb82de59a6f7ec71ddfd86a602f
Author: Chen Gong <chen.sst@gmail.com>
Date:   Sun Jan 16 00:49:47 2022 +0800

commit df4fe3e
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Aug 10 10:18:38 2021 +0100

Closes #476
lotem added a commit that referenced this issue Jan 15, 2022
As noted in #462, including <cmath> only guarantees that std::exp is
declared, so calling exp(double) unqualified is not portable.

Squashed commit with a style change to the original PR:

commit 8b9d48c0340f3fb82de59a6f7ec71ddfd86a602f
Author: Chen Gong <chen.sst@gmail.com>
Date:   Sun Jan 16 00:49:47 2022 +0800

commit df4fe3e
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Aug 10 10:18:38 2021 +0100

Closes #476
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants