使用 emscripten 生成 python.cc.js
Posted
技术标签:
【中文标题】使用 emscripten 生成 python.cc.js【英文标题】:Generating python.cc.js using emscripten 【发布时间】:2012-01-29 09:15:17 【问题描述】:我正在阅读此处的 emscripten 教程 - https://github.com/kripken/emscripten/wiki/Tutorial,并在我的本地计算机上查看源代码中的一些演示项目。
到目前为止,我已经下载了源代码并正确设置了我的 .emscripten 设置文件。
我正在寻找参考以了解:为了创建/输出“python.cc.js”和“python.html”需要哪些系列的 emcc 命令?感谢之前尝试过 emscripten 的开发人员提供的任何提示。
这是我的 .emscripten 文件:
EMSCRIPTEN_ROOT = os.path.expanduser('~/Dev/emscripten') # this helps projects using emscripten find it
# LLVM_ROOT = os.path.expanduser('~/Dev/llvm-3.0/cbuild/bin')
LLVM_ROOT = os.path.expanduser('/opt/local/bin')
# See below for notes on which JS engine(s) you need
NODE_JS = 'node'
SPIDERMONKEY_ENGINE = [os.path.expanduser('~/Dev/mozilla-central/js/src/js'), '-m', '-n']
V8_ENGINE = os.path.expanduser('~/Dev/v8/d8')
CLOSURE_COMPILER = os.path.expanduser('~/work/closure-compiler/compiler.jar') # optional (needed for the benchmarks)
TEMP_DIR = '/tmp'
########################################################################################################
# Pick the JS engine to use for running the compiler. This engine must exist, or
# nothing can be compiled.
#
# Recommendation: If you already have node installed, use that. Otherwise, build v8 or
# spidermonkey from source. Any of these three is fine, as long as it's
# a recent version (especially for v8 and spidermonkey).
COMPILER_ENGINE = NODE_JS
#COMPILER_ENGINE = V8_ENGINE
#COMPILER_ENGINE = SPIDERMONKEY_ENGINE
# All JS engines to use when running the automatic tests. Not all the engines in this list
# must exist (if they don't, they will be skipped in the test runner).
#
# Recommendation: If you already have node installed, use that. If you can, also build
# spidermonkey from source as well to get more test coverage (node can't
# run all the tests due to node issue 1669). v8 is currently not recommended
# here because of v8 issue 1822.
JS_ENGINES = [NODE_JS, SPIDERMONKEY_ENGINE]
这是我正在运行的emconfigure ./configure
命令:
calvins-MacBook ttys000 Sun Feb 05 11:47:32 |~/community/Python-2.7.2|
calvin$ emconfigure ./configure
checking for --enable-universalsdk... no
checking for --with-universal-archs... 32-bit
checking MACHDEP... darwin
checking EXTRAPLATDIR... $(PLATMACDIRS)
checking machine type as reported by uname -m... x86_64
checking for --without-gcc... no
checking for gcc... /Users/calvin/work/emscripten/emcc
checking whether the C compiler works... no
configure: error: in `/Users/calvin/community/Python-2.7.2':
configure: error: C compiler cannot create executables
See `config.log' for more details
这是生成的 config.log:
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by python configure 2.7, which was
generated by GNU Autoconf 2.68. Invocation command line was
$ ./configure
## --------- ##
## Platform. ##
## --------- ##
hostname = calvins-MacBook.local
uname -m = x86_64
uname -r = 11.2.0
uname -s = Darwin
uname -v = Darwin Kernel Version 11.2.0: Tue Aug 9 20:54:00 PDT 2011; root:xnu-1699.24.8~1/RELEASE_X86_64
/usr/bin/uname -p = i386
/bin/uname -X = unknown
/bin/arch = unknown
/usr/bin/arch -k = unknown
/usr/convex/getsysinfo = unknown
/usr/bin/hostinfo = Mach kernel version:
Darwin Kernel Version 11.2.0: Tue Aug 9 20:54:00 PDT 2011; root:xnu-1699.24.8~1/RELEASE_X86_64
Kernel configured for up to 2 processors.
2 processors are physically available.
2 processors are logically available.
Processor type: i486 (Intel 80486)
Processors active: 0 1
Primary memory available: 4.00 gigabytes
Default processor set: 146 tasks, 635 threads, 2 processors
Load average: 1.21, Mach factor: 0.99
/bin/machine = unknown
/usr/bin/oslevel = unknown
/bin/universe = unknown
PATH: ~/work/emscripten
PATH: ~/node_modules/.bin
PATH: /opt/local/apache2/bin
PATH: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin
PATH: /opt/local/lib/postgresql90/bin
PATH: /opt/local/bin
PATH: /usr/bin
PATH: ~/node_modules/.bin
PATH: /opt/local/apache2/bin
PATH: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin
PATH: /opt/local/lib/postgresql90/bin
PATH: /opt/local/bin
PATH: /usr/bin
PATH: /opt/local/bin
PATH: /opt/local/sbin
PATH: /usr/local/bin
PATH: /usr/bin
PATH: /bin
PATH: /usr/sbin
PATH: /sbin
PATH: /usr/X11/bin
## ----------- ##
## Core tests. ##
## ----------- ##
configure:2764: checking for --enable-universalsdk
configure:2805: result: no
configure:2814: checking for --with-universal-archs
configure:2831: result: 32-bit
configure:2988: checking MACHDEP
configure:3136: result: darwin
configure:3142: checking EXTRAPLATDIR
configure:3157: result: $(PLATMACDIRS)
configure:3168: checking machine type as reported by uname -m
configure:3171: result: x86_64
configure:3184: checking for --without-gcc
configure:3228: result: no
configure:3289: checking for gcc
configure:3316: result: /Users/calvin/work/emscripten/emcc
configure:3545: checking for C compiler version
configure:3554: /Users/calvin/work/emscripten/emcc --version >&5
emcc (Emscripten GCC-like replacement) 2.0
Copyright (C) 2011 the Emscripten authors.
This is free and open source software under the MIT license.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
configure:3565: $? = 0
configure:3554: /Users/calvin/work/emscripten/emcc -v >&5
Apple clang version 3.0 (tags/Apple/clang-211.10.1) (based on LLVM 3.0svn)
Target: x86_64-apple-darwin11.2.0
Thread model: posix
clang: warning: argument unused during compilation: '-nostdinc'
clang: warning: argument unused during compilation: '-nostdinc++'
clang: warning: argument unused during compilation: '-Xclang -nobuiltininc'
clang: warning: argument unused during compilation: '-Xclang -nostdinc++'
clang: warning: argument unused during compilation: '-Xclang -nostdsysteminc'
clang: warning: argument unused during compilation: '-Xclang -isystem/Users/calvin/work/emscripten/system/include'
clang: warning: argument unused during compilation: '-Xclang -isystem/Users/calvin/work/emscripten/system/include/bsd'
... rest of stderr output deleted ...
configure:3565: $? = 0
configure:3554: /Users/calvin/work/emscripten/emcc -V >&5
clang: error: argument to '-V' is missing (expected 1 value)
clang: error: no input files
configure:3565: $? = 1
configure:3554: /Users/calvin/work/emscripten/emcc -qversion >&5
clang: error: no input files
configure:3565: $? = 1
configure:3585: checking whether the C compiler works
configure:3607: /Users/calvin/work/emscripten/emcc conftest.c >&5
error: unknown argument: '-nostdsysteminc'
configure:3611: $? = 1
configure:3649: result: no
configure: failed program was:
| /* confdefs.h */
| #define _GNU_SOURCE 1
| #define _NETBSD_SOURCE 1
| #define __BSD_VISIBLE 1
| #define _BSD_TYPES 1
| #define _DARWIN_C_SOURCE 1
| /* end confdefs.h. */
|
| int
| main ()
|
|
| ;
| return 0;
|
configure:3654: error: in `/Users/calvin/community/Python-2.7.2':
configure:3656: error: C compiler cannot create executables
See `config.log' for more details
## ---------------- ##
## Cache variables. ##
## ---------------- ##
ac_cv_env_CC_set=set
ac_cv_env_CC_value=/Users/calvin/work/emscripten/emcc
ac_cv_env_CFLAGS_set=set
ac_cv_env_CFLAGS_value=
ac_cv_env_CPPFLAGS_set=
ac_cv_env_CPPFLAGS_value=
ac_cv_env_CPP_set=
ac_cv_env_CPP_value=
ac_cv_env_LDFLAGS_set=
ac_cv_env_LDFLAGS_value=
ac_cv_env_LIBS_set=
ac_cv_env_LIBS_value=
ac_cv_env_build_alias_set=
ac_cv_env_build_alias_value=
ac_cv_env_host_alias_set=
ac_cv_env_host_alias_value=
ac_cv_env_target_alias_set=
ac_cv_env_target_alias_value=
ac_cv_prog_ac_ct_CC=/Users/calvin/work/emscripten/emcc
## ----------------- ##
## Output variables. ##
## ----------------- ##
AR='/Users/calvin/work/emscripten/emar'
ARCH_RUN_32BIT=''
ARFLAGS=''
BASECFLAGS=''
BLDLIBRARY=''
BLDSHARED=''
BUILDEXEEXT=''
CC='/Users/calvin/work/emscripten/emcc'
CCSHARED=''
CFLAGS=''
CFLAGSFORSHARED=''
CONFIGURE_MACOSX_DEPLOYMENT_TARGET=''
CONFIG_ARGS=' '\''CC=/Users/calvin/work/emscripten/emcc'\'' '\''CFLAGS='\'''
CPP=''
CPPFLAGS=''
CXX='/Users/calvin/work/emscripten/em++'
DEFS=''
DLINCLDIR=''
DLLLIBRARY=''
DYNLOADFILE=''
ECHO_C='\c'
ECHO_N=''
ECHO_T=''
EGREP=''
EXEEXT=''
EXPORT_MACOSX_DEPLOYMENT_TARGET='#'
EXTRAMACHDEPPATH='$(PLATMACPATH)'
EXTRAPLATDIR='$(PLATMACDIRS)'
FRAMEWORKALTINSTALLFIRST=''
FRAMEWORKALTINSTALLLAST=''
FRAMEWORKINSTALLAPPSPREFIX=''
FRAMEWORKINSTALLFIRST=''
FRAMEWORKINSTALLLAST=''
FRAMEWORKUNIXTOOLSPREFIX='/usr/local'
GNULD=''
GREP=''
HAS_HG=''
HAVE_GETHOSTBYNAME=''
HAVE_GETHOSTBYNAME_R=''
HAVE_GETHOSTBYNAME_R_3_ARG=''
HAVE_GETHOSTBYNAME_R_5_ARG=''
HAVE_GETHOSTBYNAME_R_6_ARG=''
HGBRANCH=''
HGTAG=''
HGVERSION=''
INSTALL_DATA=''
INSTALL_PROGRAM=''
INSTALL_SCRIPT=''
INSTSONAME=''
LDCXXSHARED=''
LDFLAGS=''
LDLAST=''
LDLIBRARY=''
LDLIBRARYDIR=''
LDSHARED=''
LIBC=''
LIBFFI_INCLUDEDIR=''
LIBM=''
LIBOBJS=''
LIBRARY=''
LIBS=''
LIBTOOL_CRUFT=''
LINKCC=''
LINKFORSHARED=''
LIPO_32BIT_FLAGS=''
LN=''
LTLIBOBJS=''
MACHDEP='darwin'
MACHDEP_OBJS=''
MAINCC=''
OBJEXT=''
OPT=''
OTHER_LIBTOOL_OPT=''
PACKAGE_BUGREPORT='http://bugs.python.org/'
PACKAGE_NAME='python'
PACKAGE_STRING='python 2.7'
PACKAGE_TARNAME='python'
PACKAGE_URL=''
PACKAGE_VERSION='2.7'
PATH_SEPARATOR=':'
PKG_CONFIG=''
PYTHONFRAMEWORK=''
PYTHONFRAMEWORKDIR='no-framework'
PYTHONFRAMEWORKIDENTIFIER='org.python.python'
PYTHONFRAMEWORKINSTALLDIR=''
PYTHONFRAMEWORKPREFIX=''
RANLIB='/Users/calvin/work/emscripten/emranlib'
RUNSHARED=''
SGI_ABI=''
SHELL='/bin/sh'
SHLIBS=''
SIGNAL_OBJS=''
SO=''
SOVERSION='1.0'
SRCDIRS=''
SVNVERSION=''
THREADHEADERS=''
THREADOBJ=''
TRUE=''
UNICODE_OBJS=''
UNIVERSALSDK=''
UNIVERSAL_ARCH_FLAGS=''
USE_SIGNAL_MODULE=''
USE_THREAD_MODULE=''
VERSION='2.7'
ac_ct_CC='/Users/calvin/work/emscripten/emcc'
bindir='$exec_prefix/bin'
build_alias=''
datadir='$datarootdir'
datarootdir='$prefix/share'
docdir='$datarootdir/doc/$PACKAGE_TARNAME'
dvidir='$docdir'
exec_prefix='NONE'
host_alias=''
htmldir='$docdir'
includedir='$prefix/include'
infodir='$datarootdir/info'
libdir='$exec_prefix/lib'
libexecdir='$exec_prefix/libexec'
localedir='$datarootdir/locale'
localstatedir='$prefix/var'
mandir='$datarootdir/man'
oldincludedir='/usr/include'
pdfdir='$docdir'
prefix='NONE'
program_transform_name='s,x,x,'
psdir='$docdir'
sbindir='$exec_prefix/sbin'
sharedstatedir='$prefix/com'
sysconfdir='$prefix/etc'
target_alias=''
## ----------- ##
## confdefs.h. ##
## ----------- ##
/* confdefs.h */
#define _GNU_SOURCE 1
#define _NETBSD_SOURCE 1
#define __BSD_VISIBLE 1
#define _BSD_TYPES 1
#define _DARWIN_C_SOURCE 1
configure: exit 77
【问题讨论】:
看起来您使用的是 OS X。Emscripten 在 Mac 上无法正常工作。您可能必须切换到 Linux。 好的,我将在我的 Arch linux 实例上尝试一下,看看是否可行。谢谢。 @CalvinCheng - 它是否适用于 Linux? 请帮忙 - 我找不到 .emscription 文件:-/它在哪里? 【参考方案1】:请参阅 Emscripten wiki 页面以了解编译项目,
http://kripken.github.io/emscripten-site/docs/compiling/Building-Projects.html
还有一个项目是把Python编译成Emscripten,empythoned,
https://github.com/replit/empythoned
我不确定它是否是最新的。
【讨论】:
欢迎来到 SO,阿隆!如果您想订阅它,我添加了 emscripten 标签 @Alon:感谢您提供的两个链接!我可以澄清命令emcc [-Ox] project.bc -o project.js
中的 project.bc
是什么吗?我知道这是“项目位代码”,但是在尝试将我的“python 解释器”转换为“python.cc.js”python js 解释器的上下文中这意味着什么?
@CalvinCheng .bc
是 LLVM 位码。 LLVM 可以有两种形式:.ll
和 .bc
。基本流程是.c -> .bc/.ll -> .js
谢谢。现在这更有意义了......尝试一下。
所以我尝试运行emconfigure ./configure
,但收到configure: error: C compiler cannot create executables
消息。上面更新了详细信息。以上是关于使用 emscripten 生成 python.cc.js的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 emscripten 生成独立的 WebAssembly
将文件名传递给 Emscripten 生成的 js 作为参数