How can I transfer JS to native machine code (using v8) - javascript

I've tried the suggest in the url:
How can I see the machine code generated by v8?
Here is what I did:
git clone https://chromium.googlesource.com/chromium/tools/depot_tools
sudo apt-get install libv8-dev
sudo apt-get install g++
sudo apt-get install libgtk2.0-dev
sudo apt-get install g++-multilib
export PATH="$PATH":`pwd`/depot_tools
fetch v8
gclient sync
make ia32.release objectprint=on disassembler=on
v8/out/ia32.release/d8 --print-all-code hello.js > output.txt
(The script is just:print("hello"))
Below are the output:
kind = STUB
major_key = JSEntryStub
compiler = unknown
Instructions (size = 131)
0x35d06040 0 55 push ebp
0x35d06041 1 89e5 mov ebp,esp
0x35d06043 3 6a02 push 0x2
......
0x35d060c2 82 c3 ret
Handler Table (size = 12)
RelocInfo (size = 23)
0x35d06047 external reference (Isolate::context_address) (0xa9533dc)
0x35d06050 external reference (Isolate::c_entry_fp_address) (0xa953410)
......
kind = STUB
major_key = JSEntryStub
compiler = unknown
Instructions (size = 131)
0x35d06120 0 55 push ebb
......
Indeed,I have a batch of code,but it doesn't vary from the input script.
By the way,the output is certainly too much(about 13M text) for a simple script.
Thanks.

With current V8 versions (5.9 or later), you probably want the --print-opt-code flag: initially, V8 generates byte code for its interpreter (which you can inspect with --print-bytecode); once a function is "hot" (i.e. a lot of time is spent executing it), it is sent to the optimizing compiler to generate machine code for it.
Note that you cannot use V8 as a general purpose JavaScript-to-machine-code compiler. The flags mentioned above are intended for debugging; there is no (supported or easy) way to produce working binaries from their output.

Related

Is numjs the equivalent of numpy in javascript? What are its dependencies to work?

I'm writing the js equivalent of a python code to perform some operations on an image like numpy.std(rgb_channel).
The load of image and getting its data is done by opencv.js (https://docs.opencv.org/3.4/d0/d84/tutorial_js_usage.html)
At the moment, I'm stuck to write this code:
numpy.std(image, axis=2) which calculates stanadard deviation of rgb channel of an image.
My question is : for writing this code in javascript, should I use numjs node module? I, also, got the source code of numjs (https://github.com/nicolaspanel/numjs).
Here is the std function in numjs:
NdArray.prototype.std = function (options) {
options = _.defaults(options, { 'ddof': 0 });
var squares = this.clone();
ops.powseq(squares.selection, 2);
var mean = this.mean();
var shapeSize = _.shapeSize(this.shape);
var variance = ops.sum(squares.selection) / (shapeSize - options.ddof) - mean * mean * shapeSize / (shapeSize - options.ddof);
return variance > 0 ? Math.sqrt(Math.abs(variance)) : 0;
};
Another question would be: some errors were thrown for installing numjs like: gyp ERR! stack Error
and errors related to MSBuild.exe and also not find python. If numjs is a pure js code, why these packages should be installed. By the way, I installed python, MSBuild.exe 2017 (according to https://www.npmjs.com/package/node-gyp), still get a bunch of errors like:
sharp node module (npm ERR! Failed at the sharp#0.20.8 install script.)
and
gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual
Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe` failed with exit code: 1
numjs' dependencies are listed here, https://www.npmjs.com/package/numjs. Most of them are pure JavaScript but sharp is using some native code (so you see gyp compilation error) and is used in the image processing feature of numjs.
If you do not need this numjs' feature, you can consider https://www.npmjs.com/package/#d4c/numjs which is published by me. It removes that image processing feature which may cause installation errors, and add some TypeScript typing.
And to answer your original questions, it is a lighter version of NumPy in JavaScript and some of NumPy functions are not supplied.

Detect Browserify broken build before committing/deploying

I'm using Browserify to bundle up my JS before pushing to my Bitbucket repo, and then using Codeship to test the build and push to Heroku.
I'm using Node/Express to serve my app, and in my index.jade I have a <script /> pointing to /dist/index.js.
A couple of times, I've mistakenly pushed my latest code with broken Browserify output, ie. the contents of /dist/index.js will be:
console.error('cannot find module XYZ')
And I've deployed this to my live app. UH OH.
I've put in a very rudimentary test which gets ran on Codeship which I'm hoping should avoid this in the future:
var exit = function() {
process.exit(1)
}
var success = function() {
process.exit(0)
}
var fs = require('fs')
var index
try {
index = fs.readFileSync(__dirname + '/../public/dist/index.js', 'utf-8')
} catch (e) {
exit()
}
if(!index){
exit()
}
var invalid = index.length < 1000
if(invalid){
return exit()
}
success()
I'm just checking if the file exists, and that the contents of the file is over 1000 characters.
Not sure if there's a specific answer to this, but would be a reasonable approach to making sure broken Browserify output never gets committed/deployed?
I haven't used Codeship before, but I have used other similar services. You haven't described how you push - I'm going to assume you're using git.
With git, this becomes easy: write a pre-push hook that will abort the push if something fails. Here's an example from a project I'm working on:
#!/bin/bash
# the protected branches
#
protected_branches='develop master'
# Check if we actually have commits to push
#
commits=`git log #{u}..`
if [ -z "$commits" ]; then
exit 0
fi
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
# is the current branch in the list of protected branchs? if so, then run the
# tests
#
if grep -q "$current_branch" <<< "$protected_branches"; then
# move into the dir containing the tests
#
pushd $(git rev-parse --show-toplevel)/contract >/dev/null
gulp test
RESULT=$?
# back to whatever dir we were in before
#
popd >/dev/null
if [ $RESULT -ne 0 ]; then
echo "-------- Failed Tests"
exit 1
fi
fi
exit 0
This is a modified version of a script I found in this blog post.
Basically, this script checks to see if I'm pushing one of the protected branches and, if so, runs my tests. If those test fail, then the push is aborted.
You could, of course, change the conditions under which the push is aborted. For example, write some code to check & see if your browserify bundle is correct and fail if it's not. You mention checking the length of your bundle - maybe something like length=$(ls -l | cut -c 30-34) and then check the value of length (sorry, I'm not a real bash guru).
The benefit of this approach is that the messed up code never leaves your local machine - you run the test locally and if it fails, the code doesn't get pushed. This is likely to be faster than running in on Codeship's service.

Compiling GMP/MPFR with Emscripten

Alright, this has been driving me insane. I've been trying this for at least a month, and no where on the internet is helping.
I followed the steps of this. Not even the example works when I do these steps, because when I do it, I get this.
bitcode ==> javascript
warning: unresolved symbol: __gmpz_cmp
warning: unresolved symbol: __gmpz_mul_ui
warning: unresolved symbol: __gmpz_submul_ui
warning: unresolved symbol: __gmpz_init_set_ui
warning: unresolved symbol: __gmpz_mul_2exp
warning: unresolved symbol: __gmpz_init
warning: unresolved symbol: __gmpz_fdiv_qr
warning: unresolved symbol: __gmpz_add
And when I run the resulting complete.js file -
missing function: __gmpz_init
-1
-1
/home/ubuntu/workspace/gmp.js/complete.js:117
throw ex;
^
abort(-1) at Error
at jsStackTrace (/home/ubuntu/workspace/gmp.js/complete.js:1045:13)
at stackTrace (/home/ubuntu/workspace/gmp.js/complete.js:1062:22)
at abort (/home/ubuntu/workspace/gmp.js/complete.js:6743:44)
at ___gmpz_init (/home/ubuntu/workspace/gmp.js/complete.js:1744:56)
at Object._main (/home/ubuntu/workspace/gmp.js/complete.js:4978:2)
at Object.callMain (/home/ubuntu/workspace/gmp.js/complete.js:6627:30)
at doRun (/home/ubuntu/workspace/gmp.js/complete.js:6681:60)
at run (/home/ubuntu/workspace/gmp.js/complete.js:6695:5)
at Object.<anonymous> (/home/ubuntu/workspace/gmp.js/complete.js:6769:1)
at Module._compile (module.js:541:32)
If this abort() is unexpected, build with -s ASSERTIONS=1 which can give more information.
These instructions are for a host running amd64 Debian Buster. It seems that GMP no longer needs 32bit to work with Emscripten (and in any case 32bit Emscripten seems no longer supported?), but I used a chroot for clean environment. After installing, my chroot was 1.6GB large. But I wouldn't recommend using it for compute-intensive code if you can avoid it, in one benchmark my native code was 15 times faster than the same code compiled with Emscripten running in nodejs...
Debian Buster chroot
mkdir emscripten
sudo debootstrap buster emscripten
sudo chroot emscripten /bin/bash
echo "deb http://security.debian.org/debian-security buster/updates main" >> /etc/apt/sources.list
apt update
apt install python cmake g++ git lzip wget nodejs m4
echo "none /dev/shm tmpfs rw,nosuid,nodev,noexec 0 0" >> /etc/fstab
mount /dev/shm
echo "none /proc proc defaults 0 0" >> /etc/fstab
mount /proc
adduser emscripten
su - emscripten
emsdk latest
At time of writing this installed
releases-upstream-b024b71038d1291ed7ec23ecd553bf2c0c8d6da6-64bit
and node-12.9.1-64bit:
git clone https://github.com/juj/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh
mkdir -p ${HOME}/opt/src
cd ${HOME}/opt/src
gmp 6.1.2
wget https://gmplib.org/download/gmp/gmp-6.1.2.tar.lz
tar xf gmp-6.1.2.tar.lz
cd gmp-6.1.2
emconfigure ./configure --disable-assembly --host none --enable-cxx --prefix=${HOME}/opt
make
make install
cd ..
mpfr 4.0.2
wget https://www.mpfr.org/mpfr-current/mpfr-4.0.2.tar.xz
wget https://www.mpfr.org/mpfr-current/allpatches
tar xf mpfr-4.0.2.tar.xz
cd mpfr-4.0.2
patch -N -Z -p1 < ../allpatches
emconfigure ./configure --host none --prefix=${HOME}/opt --with-gmp=${HOME}/opt
make
make install
cd ..
mpc 1.1.0
wget https://ftp.gnu.org/gnu/mpc/mpc-1.1.0.tar.gz
tar xf mpc-1.1.0.tar.gz
cd mpc-1.1.0
emconfigure ./configure --host none --prefix=${HOME}/opt --with-gmp=${HOME}/opt --with-mpfr=${HOME}/opt
make
make install
cd ..
hello world
Your favourite program using GMP/MPFR/MPC:
emcc -o hello.js hello.c \
${HOME}/opt/lib/libmpc.a ${HOME}/opt/lib/libmpfr.a ${HOME}/opt/lib/libgmp.a
nodejs hello.js
I found out to do it, you need to be using a 32 bit machine. I had a 64 bit machine so I chroot'ed into a 32 bit filesystem using this tutorial.
After that, everything worked well. I was making a Mandelbrot program using GMP and MPFR, and I posted the compiling script (along with the program itself) online on GitHub. Here it is. Adapt it for your own projects.
I packaged it into a NPM library called gmp-wasm. You can find a Dockerized code which builds the library within the source. It exports both low-level functions and an immutable high-level wrapper:
<script src="https://cdn.jsdelivr.net/npm/gmp-wasm"></script>
<script>
gmp.init().then(({
calculate
}) => {
// calculate() automatically deallocates all objects
// created within the callback function
const result = calculate((g) => {
const six = g.Float(1).add(5);
const res = g.Pi().div(six).sin();
return res;
});
document.write(`sin(Pi/6) = ` + result);
});
</script>
Using low-level functions:
<script src="https://cdn.jsdelivr.net/npm/gmp-wasm"></script>
<script>
gmp.init().then(({
calculate, binding
}) => {
const result = calculate((g) => {
const a = g.Float(1);
const b = g.Float(2);
const c = g.Float(0);
// c = a + b
binding.mpfr_add(c.mpfr_t, a.mpfr_t, b.mpfr_t, 0);
return c;
});
document.write(`1 + 2 = ` + result);
});
</script>

Can Emstripten compile the iostream library?

I'm on Ubuntu.
$ lsb_release -a
No LSB modules are 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 the following C++ program:
#include <iostream>
int main(){
printf("hello world\n");
}
It compiles as expected.
$ emcc -O1 -s ASM_JS=1 main.cpp
$
However, when I write a similar program using the iostream facilities:
#include <iostream>
int main(){
std::cout << "hello world" << std::endl;
}
It fails to build.
$ emcc -O1 -s ASM_JS=1 main.cpp
aborting from js compiler due to exception: unknown vector type <4 x i8> | undefined
aborting from js compiler due to exception: unknown vector type <4 x i8> | undefined
aborting from js compiler due to 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 an output - process failed? We only got: ' + output[0][-3000:]
AssertionError: Did not receive forwarded data in an output - process failed? We only 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;
do {
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') and len(open(filename + '.o.js', 'r').read()) > 0, 'Emscripten failed to generate .js: ' + str(compiler_output)
AssertionError: Emscripten failed to generate .js:
I was under the impression that Emscripten has come a long way, and is capable of compiling entire C++ games for the browser! Is there some kind of flag or configuration I missed in order to sucessfully compile portions of the C++ standard library? I know that clang/gcc compilers will link against the C++ standard shared library by default. Does the issue have something to do with that you think?
I have also tried using the command em++ in place of emcc and recieved the same error message.
If relevant, here is the default configuration that was built when running emscripten for the first time:
$ cat ~/.emscripten
# Note: If you put paths relative to the home directory, do not forget os.path.expanduser
import os
# this helps projects using emscripten find it
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 for notes on which JS engine(s) you 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 this to not use the bundled version
########################################################################################################
# Pick the JS engine to use for running the compiler. This engine must exist, or
# nothing can be compiled.
#
# Recommendation: If you already have node installed, use that. Otherwise, build v8 or
# spidermonkey from source. Any of these three is fine, as long as it's
# a recent version (especially for v8 and spidermonkey).
COMPILER_ENGINE = NODE_JS
#COMPILER_ENGINE = V8_ENGINE
#COMPILER_ENGINE = SPIDERMONKEY_ENGINE
# All JS engines to use when running the automatic tests. Not all the engines in this list
# must exist (if they don't, they will be skipped in the test runner).
#
# Recommendation: If you already have node installed, use that. If you can, also build
# spidermonkey from source as well to get more test coverage (node can't
# run all the tests due to node issue 1669). v8 is currently not recommended
# here because of v8 issue 1822.
JS_ENGINES = [NODE_JS] # add this if you have spidermonkey installed too, SPIDERMONKEY_ENGINE]
I can't seem to find a way to get the basic C++ program above to successfully compile.
First, your program compiles fine for me with emcc. Your original program (with printf) causes emcc to assume it is compiling C code and as such it will auto-include stdio.h as C does. Your second program is having more trouble, probably due to an install error (for me I had an issue like this because my version of LLVM doesn't line up with the exact version Emscripten needed.)
Unfortunately, my understanding is that this is a common problem with emscripten and auto installers like apt-get -- I had the problem with both port and brew on my Mac.
The solution is to get Emscripten through the SDK, which bundles all of the sensitive pieces together: https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html
Follow the instructions there carefully. The two problems I ran into were that it expects Python 2 to be called python2 on your system and the script to adjust your default path assumes you're using bash (if you are, it should work fine.)

Error Compiling node.js v0.10.31 for armv7

When trying to compile Node.js v0.10.31 (and v0.10.30) on Ubuntu 14.04 for use on Raspberry pi (running ARM). I'm using the following compiler flags:
export AR=arm-linux-gnueabihf-ar
export CC=arm-linux-gnueabihf-gcc
export CXX=arm-linux-gnueabihf-g++
export LINK=arm-linux-gnueabihf-g++
However I get the following error:
make -C out BUILDTYPE=Release V=1
make[1]: Entering directory `/home/ubuntu/node/out'
arm-linux-gnueabihf-g++ -pthread -rdynamic -Wl,--whole-archive /home/ubuntu/node/out/Release/libopenssl.a -Wl,--no-whole-archive -Wl,--whole-archive /home/ubuntu/node/out/Release/obj.target/deps/v8/tools/gyp/libv8_base.a -Wl,--no-whole-archive -pthread -o /home/ubuntu/node/out/Release/node -Wl,--start-group /home/ubuntu/node/out/Release/obj.target/node/src/fs_event_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/cares_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/handle_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/node.o /home/ubuntu/node/out/Release/obj.target/node/src/node_buffer.o /home/ubuntu/node/out/Release/obj.target/node/src/node_constants.o /home/ubuntu/node/out/Release/obj.target/node/src/node_extensions.o /home/ubuntu/node/out/Release/obj.target/node/src/node_file.o /home/ubuntu/node/out/Release/obj.target/node/src/node_http_parser.o /home/ubuntu/node/out/Release/obj.target/node/src/node_javascript.o /home/ubuntu/node/out/Release/obj.target/node/src/node_main.o /home/ubuntu/node/out/Release/obj.target/node/src/node_os.o /home/ubuntu/node/out/Release/obj.target/node/src/node_script.o /home/ubuntu/node/out/Release/obj.target/node/src/node_stat_watcher.o /home/ubuntu/node/out/Release/obj.target/node/src/node_string.o /home/ubuntu/node/out/Release/obj.target/node/src/node_zlib.o /home/ubuntu/node/out/Release/obj.target/node/src/pipe_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/signal_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/string_bytes.o /home/ubuntu/node/out/Release/obj.target/node/src/stream_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/slab_allocator.o /home/ubuntu/node/out/Release/obj.target/node/src/tcp_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/timer_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/tty_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/process_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/v8_typed_array.o /home/ubuntu/node/out/Release/obj.target/node/src/udp_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/node_crypto.o /home/ubuntu/node/out/Release/obj.target/deps/openssl/libopenssl.a /home/ubuntu/node/out/Release/obj.target/deps/zlib/libchrome_zlib.a /home/ubuntu/node/out/Release/obj.target/deps/http_parser/libhttp_parser.a /home/ubuntu/node/out/Release/obj.target/deps/cares/libcares.a /home/ubuntu/node/out/Release/obj.target/deps/uv/libuv.a /home/ubuntu/node/out/Release/obj.target/deps/v8/tools/gyp/libv8_base.a /home/ubuntu/node/out/Release/obj.target/deps/v8/tools/gyp/libv8_nosnapshot.a -Wl,--end-group -lm -ldl -lrt
/home/ubuntu/node/out/Release/libopenssl.a(armcap.o): In function `OPENSSL_cpuid_setup':
armcap.c:(.text.startup+0x0): multiple definition of `OPENSSL_cpuid_setup'
/home/ubuntu/node/out/Release/libopenssl.a(cryptlib.o):cryptlib.c:(.text+0x360): first defined here
/home/ubuntu/node/out/Release/libopenssl.a(armcap.o): In function `OPENSSL_rdtsc':
armcap.c:(.text+0x36): undefined reference to `_armv7_tick'
/home/ubuntu/node/out/Release/libopenssl.a(armcap.o): In function `OPENSSL_cpuid_setup':
armcap.c:(.text.startup+0xe0): undefined reference to `_armv7_tick'
armcap.c:(.text.startup+0x10c): undefined reference to `_armv7_neon_probe'
collect2: error: ld returned 1 exit status
make[1]: *** [/home/ubuntu/node/out/Release/node] Error 1
make[1]: Leaving directory `/home/ubuntu/node/out'
make: *** [node] Error 2
Any ideas how to solve this error? Thank you!
I recently installed Node on a Raspberry Pi (do not use apt-get, even on Raspbian. If you can move to Raspbian, as far as I know Ubuntu doesn't like ARM). Try this:
$ cd /home/pi/node/ #or any directory you want
$ wget http://node-arm.herokuapp.com/node_latest_armhf.deb
$ sudo dpkg -i node_latest_armhf.deb
If you try to open the REPL ($ node) and this gives you an error, it's probably because it can't find the executable find. In that case this following command made it work for me:
$ hash -r
I used the following to install node.js on RPi.
Install Node on the Raspberry Pi in 5 minutes
The problem I found was that the latest node.js distribution (v0.10.31) did not include the precompiled version for the RPi. I had to go the last distribution that contained the precompiled node.js for the RPi (v0.10.28). Here is the link to the distribution repository:
http://nodejs.org/dist/

Categories

Resources