javascript - Can Emstripten compile the iostream library? -


i'm on ubuntu.

$ lsb_release -a no lsb modules available. distributor id: ubuntu description:    ubuntu 14.04.2 lts release:    14.04 codename:   trusty 

i installed emscripten.

$ sudo apt-get install emscripten 

i wrote following c++ program:

#include <iostream>  int main(){   printf("hello world\n"); } 

it compiles expected.

$ emcc -o1 -s asm_js=1 main.cpp $ 

however, when write similar program using iostream facilities:

#include <iostream>  int main(){   std::cout << "hello world" << std::endl; } 

it fails build.

$ emcc -o1 -s asm_js=1 main.cpp aborting js compiler due exception: unknown vector type <4 x i8> | undefined aborting js compiler due exception: unknown vector type <4 x i8> | undefined aborting js compiler due exception: unknown vector type <4 x i8> | undefined traceback (most recent call last):   file "/usr/share/emscripten/emscripten.py", line 1352, in <module>     _main(environ=os.environ)   file "/usr/share/emscripten/emscripten.py", line 1340, in _main     temp_files.run_and_clean(lambda: main(   file "/usr/share/emscripten/tools/tempfiles.py", line 39, in run_and_clean     return func()   file "/usr/share/emscripten/emscripten.py", line 1348, in <lambda>     debug_cache=debug_cache,   file "/usr/share/emscripten/emscripten.py", line 1235, in main     jcache=jcache, temp_files=temp_files, debug=debug, debug_cache=debug_cache)   file "/usr/share/emscripten/emscripten.py", line 292, in emscript     assert len(output) == 2, 'did not receive forwarded data in output - process failed? got: ' + output[0][-3000:] assertionerror: did not receive forwarded data in output - process failed? got: ((heap32[(($1)>>2)])|0);  $3=((($2)-(12))|0);  $4=$3;  $5=((heap32[(($4)>>2)])|0);  $6=$this;  $_sum=((($5)+(24))|0);  $7=(($6+$_sum)|0);  $8=$7;  $9=((heap32[(($8)>>2)])|0);  $10=($9|0)==0;  if ($10) {   stacktop=sp;return (($this)|0);  }  $12=(($__s)|0);  heap8[($12)]=0;  $13=(($__s+4)|0);  heap32[(($13)>>2)]=$this;  $_sum_i=((($5)+(16))|0);  $14=(($6+$_sum_i)|0);  $15=$14;  $16=((heap32[(($15)>>2)])|0);  $17=($16|0)==0;  {   if ($17) {    $_sum1_i=((($5)+(72))|0);    $19=(($6+$_sum1_i)|0);    $20=$19;    $21=((heap32[(($20)>>2)])|0);    $22=($21|0)==0;    if (!($22)) {     $24=((__znst3__113basic_ostreamicns_11char_traitsiceee5flushev($21))|0);    }    heap8[($12)]=1;    $26=((heap32[(($1)>>2)])|0);    $27=((($26)-(12))|0);    $28=$27;    $29=((heap32[(($28)>>2)])|0);    $_sum1=((($29)+(24))|0);    $30=(($6+$_sum1)|0);    $31=$30;    $32=((heap32[(($31)>>2)])|0);    $33=$32;    $34=$32;    $35=((heap32[(($34)>>2)])|0);    $36=(($35+24)|0);    $37=((heap32[(($36)>>2)])|0);    $38=((function_table_ii[($37)&{{{ ftm_ii }}}]($33))|0);    $39=($38|0)==-1;    if (!($39)) {     break;    }    $41=((heap32[(($1)>>2)])|0);    $42=((($41)-(12))|0);    $43=$42;    $44=((heap32[(($43)>>2)])|0);    $45=(($6+$44)|0);    $46=$45;    $_sum2=((($44)+(16))|0);    $47=(($6+$_sum2)|0);    $48=$47;    $49=((heap32[(($48)>>2)])|0);    $50=$49|1;    __znst3__18ios_base5clearej($46,$50);   }  } while(0);  __znst3__113basic_ostreamicns_11char_traitsiceee6sentryd2ev($__s);  stacktop=sp;return (($this)|0); }   function __znst3__18ios_base33__set_badbit_and_consider_rethrowev($this){  $this=($this)|0;  var $1=0,$2=0,$3=0,$4=0,$5=0,$6=0,$7=0,label=0;   $1=(($this+16)|0);  $2=((heap32[(($1)>>2)])|0);  $3=$2|1;  heap32[(($1)>>2)]=$3;  $4=(($this+20)|0);  $5=((heap32[(($4)>>2)])|0);  $6=$5&1;  $7=($6|0)==0;  if ($7) {   return;  } else {   ___cxa_rethrow();   } }   function __znst3__113basic_istreamiwns_11char_traitsiweeed0ev($this){  $this=($this)|0;  var $1=0,$2=0,label=0;   $1=(($this+8)|0);  __znst3__18ios_based2ev($1);  $2=$this;  __zdlpv($2);  return; }   function __znst3__113basic_istreamiwns_11char_traitsiweeed1ev($this){  $this=($this)|0;  var $1=0,label=0;   $1=(($this+8)|0);  __znst3__18ios_based2ev($1);  return; }   function __ztv0_n12_nst3__113basic_istreamiwns_11char_traitsiweeed0ev($this){  $this=($this)|0;  var $1=0,$2=0,$3=0,$4=0,$5=0,$6=0,$7=0,$_sum=0,$8=0,$9=0,label=0;   $1=$this;  $2=$this;  $3=((heap32[(($2)>>2)])|0);  $4=((($3)-(12))|0);  $5=$4;  $6=((heap32[(($5)>>2)])|0);  $7=(($1+$6)|0);  $_sum=((($6)+(8))|0);  $8=(($1+$_sum)|0);  $9=$8;  __znst3__18ios_based2ev($9);  __zdlpv($7);  return; }   function __ztv0_n12_nst3__113basic_istreamiwns_11char_traitsiweeed1ev($this){  $this=($this)|0;  var $1=0,$2=0,$3=0,$4=0,$5=0,$6=0,$_sum=0,$7=0,$8=0,label=0;   $1=$this;  $2=$this;  $3=((heap32[(($2)>>2)])|0);  $4=((($3)-(12))|0);  $5=$4;  $6=((heap32[(($5)>>2)])|0);  $_sum=((($6)+(8))|0);  $7=(($1+$_sum)|0);  $8=$7;  __znst3__18ios_based2ev($8);  return; }   traceback (most recent call last):   file "/usr/bin/emcc", line 1864, in <module>     final = shared.building.emscripten(final, append_ext=false, extra_args=extra_args)   file "/usr/share/emscripten/tools/shared.py", line 1276, in emscripten     assert os.path.exists(filename + '.o.js') , len(open(filename + '.o.js', 'r').read()) > 0, 'emscripten failed generate .js: ' + str(compiler_output) assertionerror: emscripten failed generate .js: 

i under impression emscripten has come long way, , capable of compiling entire c++ games browser! there kind of flag or configuration missed in order sucessfully compile portions of c++ standard library? know clang/gcc compilers link against c++ standard shared library default. issue have think?

i have tried using command em++ in place of emcc , recieved same error message.


if relevant, here default configuration built when running emscripten first time:

$ cat ~/.emscripten  # note: if put paths relative home directory, not forget os.path.expanduser  import os  # helps projects using emscripten find emscripten_root = os.path.expanduser(os.getenv('emscripten') or '/usr/share/emscripten') # directory llvm_root = os.path.expanduser(os.getenv('llvm') or '/usr/bin') # directory python = os.path.expanduser(os.getenv('python') or '/usr/bin/python2') # executable  # see below notes on js engine(s) need node_js = os.path.expanduser(os.getenv('node') or '/usr/bin/node') # executable spidermonkey_engine = [os.path.expanduser(os.getenv('spidermonkey') or 'js')] # executable v8_engine = os.path.expanduser(os.getenv('v8') or 'd8') # executable  java = 'java' # executable  temp_dir = '/tmp'  crunch = os.path.expanduser(os.getenv('crunch') or 'crunch') # executable  #closure_compiler = '..' # define not use bundled version  ########################################################################################################   # pick js engine use running compiler. engine must exist, or # nothing can compiled. # # recommendation: if have node installed, use that. otherwise, build v8 or #                 spidermonkey source. of these 3 fine, long it's #                 recent version (especially v8 , spidermonkey).  compiler_engine = node_js #compiler_engine = v8_engine #compiler_engine = spidermonkey_engine   # js engines use when running automatic tests. not engines in list # must exist (if don't, skipped in test runner). # # recommendation: if have node installed, use that. if can, build #                 spidermonkey source more test coverage (node can't #                 run tests due node issue 1669). v8 not recommended #                 here because of v8 issue 1822.  js_engines = [node_js] # add if have spidermonkey installed too, spidermonkey_engine]   

i can't seem find way basic c++ program above compile.

first, program compiles fine me emcc. original program (with printf) causes emcc assume compiling c code , such auto-include stdio.h c does. second program having more trouble, due install error (for me had issue because version of llvm doesn't line exact version emscripten needed.)

unfortunately, understanding common problem emscripten , auto installers apt-get -- had problem both port , brew on mac.

the solution emscripten through sdk, bundles of sensitive pieces together: https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html

follow instructions there carefully. 2 problems ran expects python 2 called python2 on system , script adjust default path assumes you're using bash (if are, should work fine.)


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -