Repository navigation
Description
Describe the bug
Cabal ignores --enable-static --disable-shared given in the command line, and follows the settings in ~/.cabal/config.
To Reproduce
Steps to reproduce the behavior:
-
Set the values in the
~/.cabal/configfor shared libraries and dynamic executables
Here's the~/.cabal/configI use: cabal-config.txt
$ cabal v2-build --enable-static --disable-shared
Resolving dependencies...
Build profile: -w ghc-8.6.5 -O1
In order, the following will be built (use -v for more details):
- Str2Split-0.1.0.0 (lib) (first run)
- Str2Split-0.1.0.0 (exe:Str2Split-exe) (first run)
Configuring library for Str2Split-0.1.0.0..
Preprocessing library for Str2Split-0.1.0.0..
Building library for Str2Split-0.1.0.0..
[1 of 2] Compiling Lib ( src/Lib.hs, /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/Lib.o )
[2 of 2] Compiling Paths_Str2Split ( /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/autogen/Paths_Str2Split.hs, /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/Paths_Str2Split.o )
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(Win32Utils.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(consUtils.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(mp_clz_tab.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(obprintf.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(obprntffuns.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(obvprintf.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(repl-vsnprintf.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(longlong.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(Disassembler.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(LdvProfile.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(OldARMAtomic.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(ProfilerReport.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(ProfilerReportJson.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(Profiling.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(RetainerProfile.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(RetainerSet.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(RtsDllMain.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(Evac_thr.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(Sanity.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(Scav_thr.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(EventLog.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(Elf.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(PEi386.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(elf_got.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(elf_plt.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(elf_plt_aarch64.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(elf_plt_arm.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(elf_reloc.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(elf_reloc_aarch64.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(elf_util.o) has no symbols
Preprocessing library for Str2Split-0.1.0.0..
Running Haddock on library for Str2Split-0.1.0.0..
Haddock coverage:
0% ( 0 / 5) in 'Lib'
Missing documentation for:
Module header
splitStr (src/Lib.hs:12)
chunker (src/Lib.hs:26)
splitMore (src/Lib.hs:29)
splitLess (src/Lib.hs:32)
Documentation created:
/Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/doc/html/Str2Split/index.html
Configuring executable 'Str2Split-exe' for Str2Split-0.1.0.0..
Warning: The package has an extraneous version range for a dependency on an
internal library: Str2Split -any && ==0.1.0.0, Str2Split -any && ==0.1.0.0.
This version range includes the current package but isn't needed as the
current package's library will always be used.
Preprocessing executable 'Str2Split-exe' for Str2Split-0.1.0.0..
Building executable 'Str2Split-exe' for Str2Split-0.1.0.0..
[1 of 2] Compiling Main ( app/Main.hs, /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe-tmp/Main.dyn_o )
[2 of 2] Compiling Paths_Str2Split ( /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/autogen/Paths_Str2Split.hs, /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe-tmp/Paths_Str2Split.dyn_o )
Linking /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe ...
$ otool -L /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe
/Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe:
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.100.1)
@rpath/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/libHSbase-4.12.0.0-ghc8.6.5.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/libHSghc-prim-0.5.3-ghc8.6.5.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/libHSrts_thr-ghc8.6.5.dylib (compatibility version 0.0.0, current version 0.0.0)
Expected behavior
Executable linked with static Haskell libraries.
System information
- MacOS Catalina 10.15.4, Xcode-11.4.
cabal-3.2.0.0,ghc8.8.3, 8.6.5.
Additional context
Here's my small test-project https://github.com/mouse07410/Str2Split.git
Attempts to build anything (demonstrating on this fairly simple reproducer project) with --enable-executable-static fails with:
$ cabal build --enable-static --disable-shared --enable-executable-static
Build profile: -w ghc-8.6.5 -O1
In order, the following will be built (use -v for more details):
- Str2Split-0.1.0.0 (lib) (configuration changed)
- Str2Split-0.1.0.0 (exe:Str2Split-exe) (configuration changed)
Configuring library for Str2Split-0.1.0.0..
cabal: --enable-executable-dynamic and --enable-executable-static are
incompatible with each other.
cabal: Failed to build Str2Split-0.1.0.0 (which is required by
exe:Str2Split-exe from Str2Split-0.1.0.0). The failure occurred during the
configure step.
With --enable-executable-static --disable-executable-dynamic fail because of the OS constraints.
$ cabal build --enable-static --disable-shared --enable-executable-static --disable-executable-dynamic
. . . . .
Linking /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe ...
ld: library not found for -lcrt0.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`clang' failed in phase `Linker'. (Exit code: 1)
Activity
asr commentedon Jul 10, 2020
I noted the same behaviour with various libraries using a
.cabal/configfile where any related to shared/static/dynamic is commented out. For example:Note that
ghcis called with the option-dynamic-too.Versions: GHC 8.10.1 and
cabal-install3.2.0.0.Blocking agda/agda#4796.
Mikolaj commentedon Jul 16, 2021
Related to #7236.
[-]Cabal fails to respect build flags --enable-static[/-][+]`cabal v2-build` fails to overwrite global config with `--enable-static` [/+]jneira commentedon Mar 25, 2022
@mouse07410 do we know if global config is overridden by cabal
project config, top level or package specific? thanks!
jneira commentedon Mar 25, 2022
@asr thanks for the info, however the command you tried is install and I am afraid the behaviour can be different for build, for better or worse
the install case is being covered in #7236
jneira commentedon Mar 25, 2022
in fact I am tempted to close this in favour the more general #7236, do you agree @mouse07410 ?
[-]`cabal v2-build` fails to overwrite global config with `--enable-static` [/-][+]`cabal v2-build` fails to overridee global config with `--enable-static --disable-shared`[/+][-]`cabal v2-build` fails to overridee global config with `--enable-static --disable-shared`[/-][+]`cabal v2-build` fails to override global config with `--enable-static --disable-shared`[/+]mouse07410 commentedon Mar 25, 2022
I've no idea, and don't fully understand the question. It appears that the global config settings take precedence over the CLI switches passed to Cabal invocation - which is the problem this issue points at.
Decision is yours - but I don't think #7236 is more general, on the contrary: #7236 is about failure to strip the built executable when the build is static. This issue is about failing to build static regardless of the CLI flags, when the global config says otherwise.
jneira commentedon Mar 25, 2022
I wanted to mean if you add to your cabal project:
or
do they override the global cabal config?
yeah i misunderstood the linked issue, sorry
mouse07410 commentedon Mar 25, 2022
Honestly, I haven't tried that (yet? ;) ).
But the goal was to make something like
cabal build --enable-staticwork, as opposed to modifying the project (or even global config) to accomplish it.Also, it is unclear whether this problem extends to
cabal install xyz --enable-static. For example, I may want most (all?) of my installed packages - both local and from Hackage - to be dynamically linked. But for some I may need to build/install them static...jneira commentedon Mar 26, 2022
well so a workaround could be to have dynamic in the global config and set static for the few exceptions in their cabal.project(.local), you exchange write or update a config file for avoid the flag in each invocation
but a workaround, the cli flag should override any previous config for sure
mouse07410 commentedon Mar 27, 2022
Alas, no.
Same result - it still links dynamically after putting
static: trueinto either one of those files (BTW, what's the purpose and the differences betweencabal.projectandcabal.project.local?):BTW, this is with Cabal-3.6.2.0, and GHC-9.0.2.
jneira commentedon Mar 27, 2022
cabal.project.localis automatically merged with the maincabal.project, the idea is to have local specific and/or temporal options in the.localone and no upload it to cvsugh, not sure if i will have time but i would like to reproduce in linux with
-v3, just in case the verbose output give us a cluemouse07410 commentedon Mar 27, 2022
Explain please. First, I might be able to reproduce it in Linux, as I have a couple of Linux VMs. Second - what do you mean by
-v3? How exactly would you like to generate "verbose output"?jneira commentedon Mar 27, 2022
sorry didn't want to bother you with more testing so I was thinking in reproduce the error setting the
-v3cabal cli option to make it produce full verbose output and try to gather some insight from, but if you have time to attach such output, it would be greatmouse07410 commentedon Mar 27, 2022
Here's the output of
cabal -v3 build --enable-shared --disable-staticon Mac:cabal-static1.log.txt
Then I started experimenting with adding stuff to
cabal.project.local, and got this:As you see, the above executable is static "enough" - as static as you can expect on MacOS, because system libraries are dynamic only.
Finally, I tried adding
--disable-executable-dynamicto CLI options:Not even sure what this all means. It appears that to statically link an executable, the only CLI flag I need is
--disable-executable-dynamic?!Size difference (for this extremely trivial app):
P.S. Did not even need to get to Linux. ;-)