I am trying to generate javascript from python using cython and emscripten.
hello.py
:
print 'Hello world.'
Then I compile this to c using cython
>>> cython --embed hello.py -v
This generates a hello.c
file which I compile with
>>> gcc hello.c -I/usr/include/python2.7/ -lpython2.7
This works for gcc or clang.
When I execute ./a.out
I get the expected output
>>> ./a.out
>>> Hello world
next I want to compile hello.c
to javascript using emscripten
>>> emcc hello.c -I/usr/include/python2.7/ -lpython2.7
I get
>>> WARNING emcc: -I or -L of an absolute path encountered.
>>> If this is to a local system header/library, it may cause problems
>>> (local system files make sense for compiling natively on your system,
>>> but not necessarily to JavaScript)
>>> clang: warning: argument unused during compilation: '-nostdinc++'
It still generates a a.out.js
file which I try to run in node.js
>>> node a.out.js
I get a reference error
>>> ReferenceError: _Py_SetProgramName is not defined
I tried changing the generated javscript a little bit, but basically I think all the _Py_
functions are not defined.
Does anyone have any experience with this, or any suggested fixes?
You will need to compile the embedabble python library -lpython2.7
to javacsript too so that it is available for your javacsript program.
Thankfully, the work to do this has already been done in empythoned. Which provides an embedded python compiled to Javascript.
You should be able to use empythoned to provide the missing _Py_SetProgramName
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With