Last active
August 29, 2015 14:19
-
-
Save rodneyrehm/e4e7bdbc02be6196f50b to your computer and use it in GitHub Desktop.
emscripten and unicode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <title>index</title> | |
| </head> | |
| <body> | |
| <script> | |
| function runForrest() { | |
| var result = Module.ccall( | |
| // C function to call | |
| 'test', | |
| // return type | |
| null, | |
| // parameter types | |
| [], | |
| // arguments for invocation | |
| [] | |
| ); | |
| } | |
| var Module = { | |
| onRuntimeInitialized: function() { | |
| setTimeout(runForrest, 200); | |
| } | |
| }; | |
| </script> | |
| <script src="test.js"></script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CC ?= gcc | |
| CXX ?= g++ | |
| CFLAGS ?= -Wall -O2 -fPIC -stdlib=libc++ | |
| CXXFLAGS ?= -Wall -O2 -fPIC -stdlib=libc++ | |
| LDFLAGS ?= -Wall -O2 -fPIC -stdlib=libc++ -Wl,--no-undefined | |
| SOURCES = \ | |
| test.cpp | |
| CSOURCES = | |
| OBJECTS = $(SOURCES:.cpp=.o) | |
| COBJECTS = $(CSOURCES:.c=.o) | |
| static: test.a | |
| test.a: $(COBJECTS) $(OBJECTS) | |
| $(AR) rcvs $@ $(COBJECTS) $(OBJECTS) | |
| js-debug: static | |
| emcc test.a -o test.js \ | |
| -O0 \ | |
| -s EXPORTED_FUNCTIONS="['_test']" \ | |
| -s DISABLE_EXCEPTION_CATCHING=0 \ | |
| -s ALLOW_MEMORY_GROWTH=1 \ | |
| -s ASSERTIONS=1 \ | |
| -s SAFE_HEAP=1 \ | |
| -s DEMANGLE_SUPPORT=1 \ | |
| --profiling-funcs \ | |
| --minify 0 \ | |
| --memory-init-file 1 | |
| %.o: %.c | |
| $(CC) $(CFLAGS) -c -o $@ $< | |
| %.o: %.cpp | |
| $(CXX) $(CXXFLAGS) -c -o $@ $< | |
| %: %.o static | |
| $(CXX) $(CXXFLAGS) -o $@ $+ $(LDFLAGS) $(LDLIBS) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ➜ emmake make js-debug | |
| /usr/local/Cellar/emscripten/1.30.5/libexec/em++ -Wall -O2 -fPIC -stdlib=libc++ -c -o test.o test.cpp | |
| /usr/local/Cellar/emscripten/1.30.5/libexec/emar rcvs test.a test.o | |
| emcc test.a -o test.js \ | |
| -O0 \ | |
| -s EXPORTED_FUNCTIONS="['_test']" \ | |
| -s DISABLE_EXCEPTION_CATCHING=0 \ | |
| -s ALLOW_MEMORY_GROWTH=1 \ | |
| -s ASSERTIONS=1 \ | |
| -s SAFE_HEAP=1 \ | |
| -s DEMANGLE_SUPPORT=1 \ | |
| --profiling-funcs \ | |
| --minify 0 \ | |
| --memory-init-file 1 | |
| WARNING root: enabling js opts for SAFE_HEAP | |
| warning: emitted code will contain very large numbers of local variables, which is bad for performance (build to JS with -O2 or above to avoid this - make sure to do so both on source files, and during 'linking') | |
| Traceback (most recent call last): | |
| File "/usr/local/Cellar/emscripten/1.30.5/libexec/emscripten.py", line 1711, in <module> | |
| _main(environ=os.environ) | |
| File "/usr/local/Cellar/emscripten/1.30.5/libexec/emscripten.py", line 1699, in _main | |
| temp_files.run_and_clean(lambda: main( | |
| File "/usr/local/Cellar/emscripten/1.30.5/libexec/tools/tempfiles.py", line 39, in run_and_clean | |
| return func() | |
| File "/usr/local/Cellar/emscripten/1.30.5/libexec/emscripten.py", line 1707, in <lambda> | |
| DEBUG_CACHE=DEBUG_CACHE, | |
| File "/usr/local/Cellar/emscripten/1.30.5/libexec/emscripten.py", line 1594, in main | |
| jcache=jcache, temp_files=temp_files, DEBUG=DEBUG, DEBUG_CACHE=DEBUG_CACHE) | |
| File "/usr/local/Cellar/emscripten/1.30.5/libexec/emscripten.py", line 964, in emscript_fast | |
| const = str(v) | |
| UnicodeEncodeError: 'ascii' codec can't encode character u'\u2026' in position 24: ordinal not in range(128) | |
| Traceback (most recent call last): | |
| File "/usr/local/bin/emcc", line 1340, in <module> | |
| final = shared.Building.emscripten(final, append_ext=False, extra_args=extra_args) | |
| File "/usr/local/Cellar/emscripten/1.30.5/libexec/tools/shared.py", line 1569, in emscripten | |
| assert os.path.exists(filename + '.o.js'), 'Emscripten failed to generate .js' | |
| AssertionError: Emscripten failed to generate .js | |
| make: *** [js-debug] Error 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <cstdlib> | |
| #include <cstring> | |
| #include "test.hpp" | |
| #include <emscripten.h> | |
| void test() { | |
| EM_ASM( console.log("hello world…") ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef _TEST_H | |
| #define _TEST_H | |
| #ifdef __cplusplus | |
| extern "C" { | |
| using namespace std; | |
| #endif | |
| void test(); | |
| #ifdef __cplusplus | |
| } | |
| #endif | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment