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

编译时报错:除以0 #121

Closed
links-zhang opened this issue Aug 23, 2023 · 14 comments
Closed

编译时报错:除以0 #121

links-zhang opened this issue Aug 23, 2023 · 14 comments
Assignees

Comments

@links-zhang
Copy link

./yacl/base/dynamic_bitset.h:2294:20: error: division by zero is not a constant expression
2294 | constexpr size_t init_val_required_blocks = u128_bits_number / bits_per_block;

@anakinxc
Copy link
Collaborator

Hi @Francis-zlh

能提供一下具体的 repro steps 吗

@links-zhang
Copy link
Author

links@links-virtual-machine:~/yacl/yacl-main$ bazel build //... -c opt
Starting local Bazel server and connecting to it...
INFO: Analyzed 218 targets (110 packages loaded, 9500 targets configured).
INFO: Found 218 targets...
ERROR: /home/links/yacl/yacl-main/yacl/crypto/utils/BUILD.bazel:19:16: Compiling yacl/crypto/utils/rand.cc failed: (Exit 1): gcc failed: error executing command (from target //yacl/crypto/utils:rand) /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections ... (remaining 46 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
In file included from ./yacl/crypto/utils/rand.h:27,
from yacl/crypto/utils/rand.cc:15:
./yacl/base/dynamic_bitset.h: In instantiation of 'constexpr yacl::dynamic_bitset<Block, Allocator>::dynamic_bitset(yacl::dynamic_bitset<Block, Allocator>::size_type, uint128_t, const allocator_type&) [with Block = __int128 unsigned; Allocator = std::allocator<__int128 unsigned>; yacl::dynamic_bitset<Block, Allocator>::size_type = long unsigned int; uint128_t = __int128 unsigned; yacl::dynamic_bitset<Block, Allocator>::allocator_type = std::allocator<__int128 unsigned>]':
yacl/crypto/utils/rand.cc:156:1: required from here
./yacl/base/dynamic_bitset.h:2294:20: error: division by zero is not a constant expression
2294 | constexpr size_t init_val_required_blocks = u128_bits_number/bits_per_block;
| ^~~~~~~~~~~~~~~~~~~~~~~~
INFO: Elapsed time: 20.630s, Critical Path: 13.60s
INFO: 13 processes: 13 internal.
FAILED: Build did NOT complete successfully

我尝试过把static constexpr size_type bits_per_block = std::numeric_limits<block_type>::digits;修改为
static constexpr size_type bits_per_block = 128;之后编译成功,并且tpre_test可以正常运行

@anakinxc
Copy link
Collaborator

麻烦提供一下 gcc 版本

@links-zhang
Copy link
Author

使用过13.2.0和10.3.0均报错

@anakinxc
Copy link
Collaborator

我们目前用的 11.2~11.4,你试一下

@links-zhang
Copy link
Author

inks@links-virtual-machine:/yacl/yacl-main$ gcc -v
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/11.4.0/lto-wrapper
目标:x86_64-pc-linux-gnu
配置为:../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
线程模型:posix
Supported LTO compression algorithms: zlib
gcc 版本 11.4.0 (GCC)
links@links-virtual-machine:
/yacl/yacl-main$ bazel build //... -c opt
INFO: Analyzed 218 targets (0 packages loaded, 0 targets configured).
INFO: Found 218 targets...
ERROR: /home/links/yacl/yacl-main/yacl/crypto/utils/BUILD.bazel:19:16: Compiling yacl/crypto/utils/rand.cc failed: (Exit 1): gcc failed: error executing command (from target //yacl/crypto/utils:rand) /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections ... (remaining 46 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
In file included from ./yacl/crypto/utils/rand.h:27,
from yacl/crypto/utils/rand.cc:15:
./yacl/base/dynamic_bitset.h: In instantiation of 'constexpr yacl::dynamic_bitset<Block, Allocator>::dynamic_bitset(yacl::dynamic_bitset<Block, Allocator>::size_type, uint128_t, const allocator_type&) [with Block = __int128 unsigned; Allocator = std::allocator<__int128 unsigned>; yacl::dynamic_bitset<Block, Allocator>::size_type = long unsigned int; uint128_t = __int128 unsigned; yacl::dynamic_bitset<Block, Allocator>::allocator_type = std::allocator<__int128 unsigned>]':
yacl/crypto/utils/rand.cc:156:1: required from here
./yacl/base/dynamic_bitset.h:2295:20: error: division by zero is not a constant expression
2295 | constexpr size_t init_val_required_blocks = u128_bits_number/bits_per_block;
| ^~~~~~~~~~~~~~~~~~~~~~~~
INFO: Elapsed time: 10.391s, Critical Path: 9.09s
INFO: 13 processes: 13 internal.
FAILED: Build did NOT complete successfully

我更换了gcc11.4以后依然有这个问题😂

@anakinxc
Copy link
Collaborator

Interesting, 请问一下你的 OS 信息还有 gcc 是怎么安装的

@links-zhang
Copy link
Author

我不太明白OS信息是如何安装的,gcc是通过下载gcc的release后通过下述命令安装
./contrib/download_prerequisites
./configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
make
make install

@links-zhang
Copy link
Author

@anakinxc
Copy link
Collaborator

就是你 linux 用的是哪个发行版?比如 Ubuntu 22.04, Centos 8 这样

@links-zhang
Copy link
Author

ubuntu 20.04

@anakinxc
Copy link
Collaborator

请用包管理器来安装 gcc

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update && sudo apt install gcc-11 g++-11
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 110 --slave /usr/bin/g++ g++ /usr/bin/g++-11 --slave /usr/bin/gcov gcov /usr/bin/gcov-11 --slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-11 --slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-11  --slave /usr/bin/cpp cpp /usr/bin/cpp-11;

然后确定一下

gcc -v

返回的是 11

@links-zhang
Copy link
Author

非常感谢您的帮助,现在已经编译成功。
--slave /usr/bin/cpp cpp /usr/bin/cpp-11应该要和其他的命令分开使用,否则会报错
还是gcc的版本的问题,但是不懂为什么release的不行😂
再次感谢您的帮助!

@anakinxc
Copy link
Collaborator

非常感谢您的帮助,现在已经编译成功。 --slave /usr/bin/cpp cpp /usr/bin/cpp-11应该要和其他的命令分开使用,否则会报错 还是gcc的版本的问题,但是不懂为什么release的不行😂 再次感谢您的帮助!

自己编译 gcc 容易缺东西,比如 libstdc++ 之类的

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

3 participants