10 |
10 |
11 You can follow the steps here to set up emscripten: https://github.com/kripken/emscripten/wiki/Tutorial |
11 You can follow the steps here to set up emscripten: https://github.com/kripken/emscripten/wiki/Tutorial |
12 |
12 |
13 Be sure to set up the correct path in ~/.emscripten. The default paths are mostly not suitable for you. |
13 Be sure to set up the correct path in ~/.emscripten. The default paths are mostly not suitable for you. |
14 |
14 |
15 Building llvm 3.0 from source has one big advantage since you can point the LLVM_ROOT to where you built it, which won't affect your local version (if it is not 3.0). |
15 Building llvm 3.0 from source has one big advantage since you can point the LLVM_ROOT to where you build it, which won't affect your local version (if it is not 3.0). |
16 |
16 |
17 = Potential problems = |
17 = Potential problems = |
18 |
18 |
19 #1 Make sure your node.js is the latest version, earlier versions won't work for some reasons; |
19 # Make sure your node.js is the latest version, earlier versions won't work for some reasons; |
20 |
20 # Make sure the version of your llvm and clang is exactly 3.0. Lower versions won't compile and higher versions may fail in some cases due to the removal of llvm-ld. For Ubuntu users, 11.10 doesn't have pre-built llvm 3.0 packages so you have to build from source files. I haven't tried llvm 3.1 (which should work in theory), but to make it less troublesome, llvm 3.0 is recommended. |
21 #2 Make sure the version of your llvm and clang is exactly 3.0. Lower versions won't compile and higher versions may fail in some cases due to the removal of llvm-ld. For Ubuntu users, 11.10 doesn't have pre-built llvm 3.0 packages so you have to build from source files. I haven't tried llvm 3.1 (which should work in theory), but to make it less troublesome, llvm 3.0 is recommended. |
|
22 |
21 |
23 = How to get llvm and clang 3.0 = |
22 = How to get llvm and clang 3.0 = |
24 |
23 |
25 If you can checkout through svn, follow the official guide (be sure the checkout release_30 branch): |
24 If you can checkout through svn, follow the official guide (checkout release_30 branch): |
26 http://llvm.org/docs/GettingStarted.html |
25 |
|
26 http://llvm.org/docs/GettingStarted.htm |
27 |
27 |
28 If you cannot checkout through svn for some network issues, you can find git mirrors in github here (which should work for everyone): |
28 If you cannot checkout through svn for some network issues, you can find git mirrors in github here (which should work for everyone): |
29 |
29 |
30 https://github.com/llvm-mirror/llvm (checkout release_30 branch) |
30 https://github.com/llvm-mirror/llvm (checkout release_30 branch) |
|
31 |
31 https://github.com/llvm-mirror/clang (checkout release_30 branch) |
32 https://github.com/llvm-mirror/clang (checkout release_30 branch) |
|
33 |
32 https://github.com/llvm-mirror/compiler-rt (checkout release_30 branch) |
34 https://github.com/llvm-mirror/compiler-rt (checkout release_30 branch) |
33 |
35 |
34 Follow the official guide to build from source code (http://llvm.org/docs/GettingStarted.html). |
36 Follow the official guide to build from source code (http://llvm.org/docs/GettingStarted.html). |
35 |
37 |
36 = Some tests = |
38 = Some tests = |
39 |
41 |
40 Here I just give some simple examples. |
42 Here I just give some simple examples. |
41 |
43 |
42 (Assume that you are in the emscripten root directory, where you can see the 'emcc' file) |
44 (Assume that you are in the emscripten root directory, where you can see the 'emcc' file) |
43 |
45 |
44 #1 hello world |
46 1. *hello world* |
45 |
47 |
46 ./emcc tests/hello_world.cpp |
48 ./emcc tests/hello_world.cpp |
47 node a.out.js |
49 node a.out.js |
48 |
50 |
49 You should be able to see "hello world!" in the terminal |
51 You should be able to see "hello world!" in the terminal |
50 |
52 |
51 If you want to have it run in browsers, you can type this (as in official tutorial): |
53 If you want to have it run in browsers, you can type this (as in official tutorial): |
52 ./emcc tests/hello_world_sdl.cpp -o hello.html |
54 ./emcc tests/hello_world_sdl.cpp -o hello.html |
53 |
55 |
54 #2 get the glgears to work in browsers |
56 2. *get the glgears to work in browsers* |
55 |
57 |
56 ./emcc tests/hello_world_gles.c -o hello_world_gles.html |
58 ./emcc tests/hello_world_gles.c -o hello_world_gles.html |
57 |
59 |
58 llvm 3.1+ won't compile this demo. The reason is that this demo uses malloc which has to been compiled first from dlmalloc. However emscripten uses llvm-ld as the linker, which has been removed in llvm 3.1+, and the result is that you will encounter some strange error messages saying that "no such file or directory". If you got this message, check your llvm and clang version. |
60 llvm 3.1+ won't compile this demo. The reason is that this demo uses malloc which has to been compiled first from dlmalloc. However emscripten uses llvm-ld as the linker, which has been removed in llvm 3.1+, and the result is that you will encounter some strange error messages saying that "no such file or directory". If you got this message, check your llvm and clang version. |
59 |
61 |
60 #3 get the file system to work |
62 3. *get the file system to work* |
61 |
63 |
62 ./emcc --preload-file hello_world_file.txt tests/hello_world_file.c -o hello_world_file.html |
64 ./emcc --preload-file hello_world_file.txt tests/hello_world_file.c -o hello_world_file.html |
63 |
65 |
64 Note that you must add "--preload-file hello_world_file.txt" in the command line. This line tells emcc that it should embed the file loading code into the js file. Before the application runs, all files will be loaded first. If you don't do this, it won't find this file. |
66 Note that you must add "--preload-file hello_world_file.txt" in the command line. This line tells emcc that it should embed the file loading code into the js file. Before the application runs, all files will be loaded first. If you don't do this, it won't find this file. |