Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node compilation option error #3207

Closed
luisfpinto opened this issue Oct 6, 2015 · 12 comments
Closed

Node compilation option error #3207

luisfpinto opened this issue Oct 6, 2015 · 12 comments
Labels
build Issues and PRs related to build files or the CI.

Comments

@luisfpinto
Copy link

Hi guys!

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

Do you know how to solve this problem?

Thank you in advance!

@jbergstroem jbergstroem added the build Issues and PRs related to build files or the CI. label Oct 6, 2015
@jbergstroem
Copy link
Member

@luisfpinto what architecture and operating system are you running on?

@luisfpinto
Copy link
Author

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
Copy link
Author

Thank you! @jbergstroem .

@mscdex
Copy link
Contributor

mscdex commented 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 bcrypt module for example). However, node modules that do not require compilation will work just fine.

@eljefedelrodeodeljefe
Copy link
Contributor

@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.

@jbergstroem
Copy link
Member

Just to be clear: the static issues on mac (-lcrt0.o) is because the clang toolchain doesn't support fully static builds.

@luisfpinto
Copy link
Author

I've also tried to compile on Ubuntu and It has the same error.

@pmclee
Copy link

pmclee commented 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:

export CC=mipsel-linux-gnu-gcc
export CXX=mipsel-linux-gnu-g++
export LINK=mipsel-linux-gnu-g++
export CFLAGS=-EL
export GYPFLAGS=-Dv8_target_arch=mipsel
./configure --fully-static --dest-cpu=mipsel --dest-os=linux && make

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?

@bnoordhuis
Copy link
Member

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
Copy link
Contributor

mscdex commented 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:

  1. Make sure your compiler and linker-related environment variables are unset first.

  2. curl -L https://github.com/GregorR/musl-cross/tarball/master | tar zx and change to the extracted directory

  3. We need to make some modifications to some files before building the cross compiler:

    1. 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.
    2. Edit defs.sh and change MUSL_DEFAULT_VERSION=1.1.10 to MUSL_DEFAULT_VERSION=1.1.11
    3. 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
  4. 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.

  5. 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

  6. Set the environment variables and compile:

    $ export CFLAGS="-I /path/to/mipsel-linux-musl/mipsel-linux-musl/include"
    $ export CXXFLAGS="-I /path/to/mipsel-linux-musl/mipsel-linux-musl/include"
    $ export CC=/path/to/mipsel-linux-musl/bin/mipsel-linux-musl-gcc
    $ export CXX=/path/to/mipsel-linux-musl/bin/mipsel-linux-musl-g++
    $ ./configure --dest-cpu=mipsel --dest-os=linux --fully-static
    $ make -j8
    

@pmclee
Copy link

pmclee commented 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
Copy link
Contributor

Closing as this seems to have been resolved. Should we perhaps document these instructions on the wiki?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issues and PRs related to build files or the CI.
Projects
None yet
Development

No branches or pull requests

7 participants