Emscripten 安装和使用
OS: Windows 10 x64
I. install
0. pre install
1. down
git clone https://github.com/emscripten-core/emsdk.git
注意:最新版本信息请查看“emscripten-tags.txt”
(1) lkgr.json
https://storage.googleapis.com/wasm-llvm/builds/linux/lkgr.json
to "emsdk\upstream"
(2) llvm
https://s3.amazonaws.com/mozilla-games/emscripten/packages/llvm/tag/win_64bit/emscripten-llvm-e1.38.30.zip
to "ëmsdk\zips"
2. setup
(1) custom install
emsdk install clang-e1.
(2) activate
emsdk activate --vs2013 clang-e1.
(3) test
emsdk_env
II. usage
1. compile BC file
emcc tests/hello_world.c
2. output
(1) normal
emcc tests/hello_world.c -o hello.html
(2) sdl
emcc tests/hello_world_sdl.cpp -o hello.html
(3) file
emcc tests/hello_world_file.cpp -o hello.html --preload-file tests/hello_world_file.txt
3. run
python -m SimpleHTTPServer
http://localhost:8080/hello.html
Src:
1. hello_world.c
/*
* Copyright 2011 The Emscripten Authors. All rights reserved.
* Emscripten is available under two separate licenses, the MIT license and the
* University of Illinois/NCSA Open Source License. Both these licenses can be
* found in the LICENSE file.
*/
#include <stdio.h>
int main() {
printf("hello, world!\n");
;
}
2. hello_world_sdl.cpp
// Copyright 2011 The Emscripten Authors. All rights reserved.
// Emscripten is available under two separate licenses, the MIT license and the
// University of Illinois/NCSA Open Source License. Both these licenses can be
// found in the LICENSE file.
#include <stdio.h>
#include <SDL/SDL.h>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
extern "C" int main(int argc, char** argv) {
printf("hello, world!\n");
SDL_Init(SDL_INIT_VIDEO);
SDL_Surface *screen = SDL_SetVideoMode(, , , SDL_SWSURFACE);
#ifdef TEST_SDL_LOCK_OPTS
EM_ASM("SDL.defaults.copyOnLock = false; SDL.defaults.discardOnLock = true; SDL.defaults.opaqueFrontBuffer = false;");
#endif
if (SDL_MUSTLOCK(screen)) SDL_LockSurface(screen);
; i < ; i++) {
; j < ; j++) {
#ifdef TEST_SDL_LOCK_OPTS
// Alpha behaves like in the browser, so write proper opaque pixels.
;
#else
// To emulate native behavior with blitting to screen, alpha component is ignored. Test that it is so by outputting
// data (and testing that it does get discarded)
;
#endif
*((Uint32*)screen->pixels + i * + j) = SDL_MapRGBA(screen->format, i, j, -i, alpha);
}
}
if (SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
SDL_Flip(screen);
printf("you should see a smoothly-colored square - no sharp lines but the square borders!\n");
printf("and here is some text that should be HTML-friendly: amp: |&| double-quote: |\"| quote: |'| less-than, greater-than, html-like tags: |<cheez></cheez>|\nanother line.\n");
SDL_Quit();
;
}
3. hello_world_file.cpp
// Copyright 2012 The Emscripten Authors. All rights reserved.
// Emscripten is available under two separate licenses, the MIT license and the
// University of Illinois/NCSA Open Source License. Both these licenses can be
// found in the LICENSE file.
#include <stdio.h>
int main() {
FILE *file = fopen("tests/hello_world_file.txt", "rb");
if (!file) {
printf("cannot open file\n");
;
}
while (!feof(file)) {
char c = fgetc(file);
if (c != EOF) {
putchar(c);
}
}
fclose (file);
;
}
hello_world_file.txt
== This data has been read from a file. The file is readable as if it were at the same location in the filesystem, including directories, as in the local filesystem where you compiled the source. ==
Reference:
Emscripten 安装和使用的更多相关文章
- WebAssembly完全入门——了解wasm的前世今身
前言 接触WebAssembly之后,在google上看了很多资料.感觉对WebAssembly的使用.介绍.意义都说的比较模糊和笼统.感觉看了之后收获没有达到预期,要么是文章中的例子自己去实操不能成 ...
- WebAssembly 上手
安装 Mac 上最便捷的安装方式当然是通过 Homebrew: $ brew install emscripten 安装好之后讲道理就已经自动配置好一切,然后 emcc 命令便可用了. 下面看非 Ho ...
- Ubuntu 18.04 下 emscripten SDK 的安装
Ubuntu 18.04 下 emscripten SDK 的安装http://kripken.github.io/emscripten-site/docs/getting_started/downl ...
- windows下安装emscripten
windows下安装emscripten windows下安装emscripten需要python.git环境 python安装 git安装 开始安装 # 1.克隆emsdk git clone ht ...
- Web字节码(WebAssembly) Emscripten编译器安装
首先你需要提前安装 git python 环境并且Ctrl+R输入cmd在windows的dos界面下能够运行 第一步: 在github上downloade下来emsdk git clone http ...
- VS2010 c/c++ 本地化 emscripten 配置
配置环境 1.下载emsdk-1.35.0-full-64bit.exe,有VS2010的话直接安装. 2.安装好之后,打开cmd,# emsdk update # emsdk install lat ...
- emscripten、 WebAssembly,传递字符串给c函数
下面看具体的实例. 下面的代码是一个C函数,实现简单的字符串拼接,然后返回拼接的字符串. #include <stdio.h> #include <string> char* ...
- Mac环境 安装brew
一.brew官网主页上的方法: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/insta ...
- mingw 搭建Emscripten 环境
mingw 环境的搭建可以参考网上很多文章,不复杂.但在搭建Emscripten 环境之前需要配置git 和python 和MSbuild.exe 还需要安装camke 默认安装之后应该是添加了 系统 ...
随机推荐
- laravel 微信小程序登录 加密解密扩展包
https://github.com/lanceWan/wxxcx 测试的时候一定要保证服务器的 appid 和客户端的appid一致 如果是切换测试 那么需要把本地的项目从微信小程序上面删除掉 再 ...
- Python标准库映射类型与可散列数据类型的关系
这里有两个概念似懂非懂,在这里明确一下: 映射类型: Python>3.2中,collections.abc模块有Mapping和MutableMapping两个抽象基类(Python2.6~3 ...
- Xshell简单介绍
Xshell介绍 Xshell 是一个强大的安全终端模拟软件,它支持SSH1, SSH2, 以及Microsoft Windows 平台的TELNET 协议.Xshell 通过互联网到远程主机的安全 ...
- Linux Nginx Web环境安装SSL证书后强行指向HTTPS方法
如今我们越来越多的网站需要使用SSL证书,尤其是一些购物类网站,用户交互类网站使用居多.安装方法也很简单,我们可以根据自己的服务器是NGINX还是APACHE进行安装,但是在安装之后,默认的HTTP和 ...
- 积累的关于linux的安装卸载软件基本命令
Linux安装.卸载软件 在linux环境中,尤其是cenos中安装过一些软件,一般是二进制安装与源码安装,现小结一下linux中的安装与卸载. 一.通常Linux应用软件的安装包有三种: 1) ...
- 判断是不是微信浏览器和QQ内置浏览器
is_weixn() { let ua = navigator.userAgent.toLowerCase(); if (ua.match(/MicroMessenger/i) == "mi ...
- ES5与ES6中的继承
ES5继承在ES5中没有类的概念,所以一般都是基于原型链继承,具体的继承方法有以下几种: 父类: function Father (name) { this.name = name || 'sam' ...
- java中int和String之间的转换
String 转为int int i = Integer.parseInt([String]); int i = Integer.valueOf(my_str).intValue(); int转为St ...
- php 图片缩放然后合成并保存
/** * 功能说明 * 将files/model_24/images/下的所有图片文件进行等比例缩放 到$image40w 尺寸 然后放到files/model_24/model.png图片的指定位 ...
- PythonStudy——列表与字典推导式 List and dictionary derivation
# 快速生成列表或字典的语法糖,且能在生成过程中添加简单的逻辑 # 能被列表推导式推导的数据源必须在循环取值时可以得到一个值 ls = [v for v in range(1, 6)] print(l ...