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

Problem with static linknig #39

Open
4e6 opened this issue Aug 15, 2018 · 2 comments
Open

Problem with static linknig #39

4e6 opened this issue Aug 15, 2018 · 2 comments

Comments

@4e6
Copy link

4e6 commented Aug 15, 2018

I'm trying to create a static executable which depends on text-icu.

Here is the minified example https://github.com/4e6/text-icu-static-example

To enable static linking, I build icu with --enable-static flag here:

  # http://userguide.icu-project.org/packaging#TOC-Link-to-ICU-statically
  icu-static = pkgs.icu.overrideAttrs (attrs: {
    dontDisableStatic = true;
    configureFlags = (attrs.configureFlags or "") + " --enable-static";
    outputs = attrs.outputs ++ [ "static" ];
    postInstall = ''
      mkdir -p $static/lib
      mv -v lib/*.a $static/lib
    '' + (attrs.postInstall or "");
  });

And add following ghc options here:

        configureFlags = [
          "--ghc-option=-optl=-static"
          "--ghc-option=-optl=-pthread"
          "--ghc-option=-optl=-L${pkgs.glibc.static}/lib"
          "--ghc-option=-optl=-L${pkgs.gmp6.override { withStatic = true; }}/lib"
          "--ghc-option=-optl=-L${icu-static.static}/lib"
        ];

As a result of nix-build ., I'm getting a lot of errors about undefined references, see nix-build.log:

/nix/store/2h1il2pyfh20kc5rh7vnp5a564alxr21-icu4c-59.1-static/lib/libicui18n.a(regexcmp.ao):(.text+0x7805): more undefined references to `icu_59::UVector64::setElementAt(long, int)' follow
/nix/store/2h1il2pyfh20kc5rh7vnp5a564alxr21-icu4c-59.1-static/lib/libicui18n.a(regexcmp.ao): In function `icu_59::RegexCompile::compile(UText*, UParseError&, UErrorCode&)':
(.text+0x8355): undefined reference to `__cxa_throw_bad_array_new_length'
/nix/store/2h1il2pyfh20kc5rh7vnp5a564alxr21-icu4c-59.1-static/lib/libicui18n.a(regexcmp.ao):(.data.rel.ro._ZTIN6icu_5912RegexCompileE[_ZTIN6icu_5912RegexCompileE]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
collect2: error: ld returned 1 exit status
`cc' failed in phase `Linker'. (Exit code: 1)

This setup works with other libraries but fails with text-icu. Any ideas on what I'm doing wrong?

@andreasabel
Copy link
Member

I tried your text-icu-static-example on macOS with latest text (had to bump the <2 bound) and text-icu. However, on macOS static linking does not seem to be supported generally:

$ cabal build --enable-executable-static
...
ld: library not found for -lcrt0.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ghc-9.4.2: `gcc' failed in phase `Linker'. (Exit code: 1)

Does the problem still persists on Linux?

@sgillespie
Copy link

I just happened to run into this as well. Adding:

build-depends: double-conversion

Seems to fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants