You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to compile nodejs with --fully-static flag, in order to get a fully statically linked executable. However, when I try to compile, this error appears:
more undefined references to `__aeabi_unwind_cpp_pr0' follow
collect2: error: ld returned 1 exit status
FWIW I've only had good luck with musl as far as compiling a fully static binary goes. Static binaries compiled with glibc still need to access shared libraries like nss modules (e.g. for resolving hostnames through dns and /etc/hosts) and such.
The one downside is that most libc implementations do not provide dlopen() when compiling statically, which is needed to load compiled node addons (like the bcrypt module for example). However, node modules that do not require compilation will work just fine.
@luisfpinto have you had a look at the wiki? It fails for me also, but due to this is expected due to Mac OS's gcc issue and so it would be expected. I see ld: library not found for -lcrt0.o rather, though.
I have a similar issue, I think. I'm cross-compiling nodejs 4.1.2 for mipsel and I've run into a snag trying to get a static binary image build.
At the moment our runtime MIPS environment is running an older linux built with gcc 3.4 -- but our application requires 4.9. It's a long story, but bottom line is that for the next couple of weeks I need to build with 4.9 and run in this older 3.4 environment -- if possible.
My strategy was to build nodejs with static libraries by building/making it like this:
But when I tried running a test "hello world" node app, I can see that something is not quite right. I'm not sure if I am reading the error messages right, either, because it appears that nodejs has somehow loaded libstdc++.so.6 (which I didn't think it would do, being statically linked). Further, it also appears that the so fails because it is looking for 3.4 libraries (which should be what is installed).
root@TestMachine:/var/node# node testServer.js
node: /lib/libc.so.6: version `GLIBC_2.19' not found (required by node)
node: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by node)
node: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by node)
So maybe I need to back up for a moment and ask some questions:
is there some different/additional config option that I should be using?
is there an environment variable that I'm missing?
or is there some other way to generate a statically linked target?
I think you'll need to make sure that your host and target machines match up (host = the system you're cross-compiling on), at least when it comes to standard libraries.
Linking glibc statically almost never works, just google for the horror stories. You could try linking in musl or uclibc instead.
Linking libstdc++ statically is probably okay (although native add-ons may not work) but you're going to have to hack the build system to ensure it links against libstdc++.a, not the .so. If your compiler knows about -static-libstdc++, I'd use that.
If you want to build one yourself, you'll need to build a cross compiler compatible with musl (if you want to use the cross compiler (uses musl 1.1.11) I built, you can get that here and skip to step 5 if you are using that). Here's what I did to build the cross compiler:
Make sure your compiler and linker-related environment variables are unset first.
curl -L https://github.com/GregorR/musl-cross/tarball/master | tar zx and change to the extracted directory
We need to make some modifications to some files before building the cross compiler:
As of this writing, patches/gcc-5.2.0-musl.patch needs to be updated to fix building on mips. Replace that existing patch file with the one from here.
Edit defs.sh and change MUSL_DEFAULT_VERSION=1.1.10 to MUSL_DEFAULT_VERSION=1.1.11
Edit config.sh and uncomment ARCH=mipsel and change CC_BASE_PREFIX to the directory where the cross compiler and related files will be stored
Now just do ./build.sh and if all goes well, it should automatically pull down all the needed sources and build the cross compiler. This will take awhile.
Download node (v4.2.1 is what I used): curl -L nodejs.org/dist/v4.2.1/node-v4.2.1.tar.xz | tar Jx and change to the extracted directory
Activity
jbergstroem commentedon Oct 6, 2015
@luisfpinto what architecture and operating system are you running on?
luisfpinto commentedon Oct 6, 2015
I' trying to compile node in two operative systems:
1)Ubuntu
2)Mac-OS.
If I compile node without --fully-static flag, I don't get any problems. But I need it.
luisfpinto commentedon Oct 6, 2015
Thank you! @jbergstroem .
mscdex commentedon Oct 6, 2015
FWIW I've only had good luck with musl as far as compiling a fully static binary goes. Static binaries compiled with glibc still need to access shared libraries like nss modules (e.g. for resolving hostnames through dns and /etc/hosts) and such.
The one downside is that most libc implementations do not provide dlopen() when compiling statically, which is needed to load compiled node addons (like the
bcryptmodule for example). However, node modules that do not require compilation will work just fine.eljefedelrodeodeljefe commentedon Oct 6, 2015
@luisfpinto have you had a look at the wiki? It fails for me also, but due to this is expected due to Mac OS's gcc issue and so it would be expected. I see
ld: library not found for -lcrt0.orather, though.jbergstroem commentedon Oct 6, 2015
Just to be clear: the static issues on mac (
-lcrt0.o) is because the clang toolchain doesn't support fully static builds.luisfpinto commentedon Oct 7, 2015
I've also tried to compile on Ubuntu and It has the same error.
pmclee commentedon Oct 13, 2015
I have a similar issue, I think. I'm cross-compiling nodejs 4.1.2 for mipsel and I've run into a snag trying to get a static binary image build.
At the moment our runtime MIPS environment is running an older linux built with gcc 3.4 -- but our application requires 4.9. It's a long story, but bottom line is that for the next couple of weeks I need to build with 4.9 and run in this older 3.4 environment -- if possible.
My strategy was to build nodejs with static libraries by building/making it like this:
But when I tried running a test "hello world" node app, I can see that something is not quite right. I'm not sure if I am reading the error messages right, either, because it appears that nodejs has somehow loaded libstdc++.so.6 (which I didn't think it would do, being statically linked). Further, it also appears that the
sofails because it is looking for 3.4 libraries (which should be what is installed).So maybe I need to back up for a moment and ask some questions:
bnoordhuis commentedon Oct 13, 2015
I think you'll need to make sure that your host and target machines match up (host = the system you're cross-compiling on), at least when it comes to standard libraries.
Linking glibc statically almost never works, just google for the horror stories. You could try linking in musl or uclibc instead.
Linking libstdc++ statically is probably okay (although native add-ons may not work) but you're going to have to hack the build system to ensure it links against libstdc++.a, not the .so. If your compiler knows about
-static-libstdc++, I'd use that.mscdex commentedon Oct 13, 2015
@pmclee I was able to build a fully static v4.2.1 binary for mipsel using musl.
If you want to build one yourself, you'll need to build a cross compiler compatible with musl (if you want to use the cross compiler (uses musl 1.1.11) I built, you can get that here and skip to step 5 if you are using that). Here's what I did to build the cross compiler:
Make sure your compiler and linker-related environment variables are unset first.
curl -L https://github.com/GregorR/musl-cross/tarball/master | tar zxand change to the extracted directoryWe need to make some modifications to some files before building the cross compiler:
patches/gcc-5.2.0-musl.patchneeds to be updated to fix building on mips. Replace that existing patch file with the one from here.defs.shand changeMUSL_DEFAULT_VERSION=1.1.10toMUSL_DEFAULT_VERSION=1.1.11config.shand uncommentARCH=mipseland changeCC_BASE_PREFIXto the directory where the cross compiler and related files will be storedNow just do
./build.shand if all goes well, it should automatically pull down all the needed sources and build the cross compiler. This will take awhile.Download node (v4.2.1 is what I used):
curl -L nodejs.org/dist/v4.2.1/node-v4.2.1.tar.xz | tar Jxand change to the extracted directorySet the environment variables and compile:
pmclee commentedon Oct 15, 2015
@mscdex -- thanks so much for the detailed instructions! As it turned out, we got the linux root fs recompiled sooner than I expected.
I followed your advice and used the 4.2.1 source. Everything seems to have built correctly and I ran a "hello, world" test app this morning.
Thanks again for the help!
evanlucas commentedon Nov 10, 2015
Closing as this seems to have been resolved. Should we perhaps document these instructions on the wiki?