好吧,这让我疯了。我已经尝试了至少一个月,而且互联网上的任何地方都没有帮助。
我按照this的步骤进行操作。当我执行这些步骤时,甚至示例都不起作用,因为当我这样做时,我得到了这个。
bitcode ==> javascript
warning: unresolved symbol: __gmpz_cmp
warning: unresolved symbol: __gmpz_mul_ui
warning: unresolved symbol: __gmpz_submul_ui
warning: unresolved symbol: __gmpz_init_set_ui
warning: unresolved symbol: __gmpz_mul_2exp
warning: unresolved symbol: __gmpz_init
warning: unresolved symbol: __gmpz_fdiv_qr
warning: unresolved symbol: __gmpz_add
当我运行生成的complete.js文件时 -
missing function: __gmpz_init
-1
-1
/home/ubuntu/workspace/gmp.js/complete.js:117
throw ex;
^
abort(-1) at Error
at jsStackTrace (/home/ubuntu/workspace/gmp.js/complete.js:1045:13)
at stackTrace (/home/ubuntu/workspace/gmp.js/complete.js:1062:22)
at abort (/home/ubuntu/workspace/gmp.js/complete.js:6743:44)
at ___gmpz_init (/home/ubuntu/workspace/gmp.js/complete.js:1744:56)
at Object._main (/home/ubuntu/workspace/gmp.js/complete.js:4978:2)
at Object.callMain (/home/ubuntu/workspace/gmp.js/complete.js:6627:30)
at doRun (/home/ubuntu/workspace/gmp.js/complete.js:6681:60)
at run (/home/ubuntu/workspace/gmp.js/complete.js:6695:5)
at Object.<anonymous> (/home/ubuntu/workspace/gmp.js/complete.js:6769:1)
at Module._compile (module.js:541:32)
If this abort() is unexpected, build with -s ASSERTIONS=1 which can give more information.
答案 0 :(得分:4)
这些说明适用于运行amd64(multiarch)Debian Stretch的主机。我尝试了三个主机,两个成功,另一个失败,ld
内存不足clang
。因人而异。正如Flarp所说,似乎GMP需要一个32位环境才能与Emscripten一起工作,因此chroot。安装后,我的chroot大5.2GB。但是我不建议将它用于计算密集型代码,如果你可以避免它,在一个基准测试中,我的本机代码比使用在nodejs中运行的Emscripten编译的相同代码快90倍...
mkdir emscripten
sudo apt-get install debootstrap
sudo debootstrap --arch i386 stretch emscripten
sudo chroot emscripten /bin/bash
echo "deb http://security.debian.org/debian-security stretch/updates main" >> /etc/apt/sources.list
echo "deb http://ftp.debian.org/debian stretch-backports main" >> /etc/apt/sources.list
apt update
apt install python cmake g++ git lzip
apt install -t stretch-backports nodejs
echo "none /dev/shm tmpfs rw,nosuid,nodev,noexec 0 0" >> /etc/fstab
mount /dev/shm
adduser emscripten
su - emscripten
git clone https://github.com/juj/emsdk.git
cd emsdk
./emsdk update
./emsdk install latest-32bit
./emsdk activate latest-32bit
source ./emsdk_env.sh
mkdir -p ${HOME}/opt/src
cd ${HOME}/opt/src
wget https://gmplib.org/download/gmp/gmp-6.1.2.tar.lz
tar xf gmp-6.1.2.tar.lz
cd gmp-6.1.2
CC_FOR_BUILD=/usr/bin/gcc ABI=standard emconfigure ./configure \
--build i686-pc-linux-gnu --host none --disable-assembly --enable-cxx \
--prefix=${HOME}/opt
make -j 6
make install
cd ..
wget https://www.mpfr.org/mpfr-current/mpfr-4.0.1.tar.xz
wget https://www.mpfr.org/mpfr-current/allpatches
tar xf mpfr-4.0.1.tar.xz
cd mpfr-4.0.1
patch -N -Z -p1 < ../allpatches
emconfigure ./configure --build i686-pc-linux-gnu --host none \
--prefix=${HOME}/opt --with-gmp=${HOME}/opt
make -j 6
make install
cd ..
wget https://ftp.gnu.org/gnu/mpc/mpc-1.1.0.tar.gz
tar xf mpc-1.1.0.tar.gz
cd mpc-1.1.0
emconfigure ./configure --build i686-pc-linux-gnu --host none \
--prefix=${HOME}/opt --with-gmp=${HOME}/opt --with-mpfr=${HOME}/opt
make -j 6
make install
cd ..
您最喜欢的使用GMP / MPFR / MPC的程序:
emcc -o hello.js hello.c \
${HOME}/opt/lib/libmpc.a ${HOME}/opt/lib/libmpfr.a ${HOME}/opt/lib/libgmp.a
nodejs hello.js
但是,最后一次emcc命令在我的最新测试中失败,并显示有关缺少binaryen的错误,请参阅https://github.com/kripken/emscripten/issues/6892
答案 1 :(得分:1)
我发现要做,你需要使用32位机器。我有一台64位机器,所以我使用this tutorial.
chroot进入32位文件系统在那之后,一切都运作良好。我正在使用GMP和MPFR制作Mandelbrot程序,并在GitHub上在线发布了编译脚本(以及程序本身)。 Here它是。适应您自己的项目。