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

Stack build causing linker error on Mac OSX Sierra #3487

Closed
td-ideabox opened this issue Oct 13, 2017 · 28 comments
Closed

Stack build causing linker error on Mac OSX Sierra #3487

td-ideabox opened this issue Oct 13, 2017 · 28 comments

Comments

@td-ideabox
Copy link

macOS 10.12.6 (16G29) (Sierra)
Fresh uninstall/reinstall of XCode (accepted terms)
brew as package manager

I blew away all stuff related to ghc, stack, and cabal and then installed this way
https://haskell-lang.org/get-started

Writing the little HelloWorld.hs script worked fine and showed Hello, World

However, doing

stack new someproj
cd someproj
stack build

Resulted in this:

➜  someproj stack build
[1 of 2] Compiling Main             ( /Users/trevord2/.stack/setup-exe-src/setup-mPHDZzAJ.hs, /Users/trevord2/.stack/setup-exe-src/setup-mPHDZzAJ.o )
[2 of 2] Compiling StackSetupShim   ( /Users/trevord2/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /Users/trevord2/.stack/setup-exe-src/setup-shim-mPHDZzAJ.o )
Linking /Users/trevord2/.stack/setup-exe-cache/x86_64-osx/tmp-Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 ...
someproj-0.1.0.0: configure (lib + exe)
Configuring someproj-0.1.0.0...
someproj-0.1.0.0: build (lib + exe)
Preprocessing library someproj-0.1.0.0...
[1 of 1] Compiling Lib              ( src/Lib.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/Lib.o )
Preprocessing executable 'someproj-exe' for someproj-0.1.0.0...
[1 of 1] Compiling Main             ( app/Main.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/someproj-exe/someproj-exe-tmp/Main.o )
Linking .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/someproj-exe/someproj-exe ...
ld: warning: ignoring file /Users/trevord2/someproj/.stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/libHSsomeproj-0.1.0.0-6corWoTDCA69pE1sqNF8Id.a, file was built for archive which is not the architecture being linked (x86_64): /Users/trevord2/someproj/.stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/libHSsomeproj-0.1.0.0-6corWoTDCA69pE1sqNF8Id.a
Undefined symbols for architecture x86_64:
  "_someprojzm0zi1zi0zi0zm6corWoTDCA69pE1sqNF8Id_Lib_someFunc1_closure", referenced from:
      _Main_main1_info in Main.o
      _S39Z_srt in Main.o
  "_someprojzm0zi1zi0zi0zm6corWoTDCA69pE1sqNF8Id_Lib_someFunc1_info", referenced from:
      _Main_main_info in Main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`gcc' failed in phase `Linker'. (Exit code: 1)

--  While building package someproj-0.1.0.0 using:
      /Users/trevord2/.stack/setup-exe-cache/x86_64-osx/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-osx/Cabal-1.24.2.0 build lib:someproj exe:someproj-exe --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1

Expected

Successful stack build

Stack version

Version 1.5.1, Git revision 600c1f01435a10d127938709556c1682ecfd694e (4861 commits) x86_64 hpack-0.17.1

Method of installation

https://haskell-lang.org/get-started

@snoyberg
Copy link
Contributor

Can you try rebuilding with GHC 8.2.1 with a command line stack build --resolver nightly-2017-10-13? It may inform as to whether there's an incompatibility between a specific GHC version and the new OS X release.

@td-ideabox
Copy link
Author

Below is what I executed:

λ ~/someproj/ stack build --install-ghc  --resolver nightly-2017-10-13
Preparing to install GHC to an isolated location.
This will not interfere with any system-level installation.
Downloaded ghc-8.2.1.
Installed GHC.
[1 of 2] Compiling Main             ( /Users/trevord2/.stack/setup-exe-src/setup-mPHDZzAJ.hs, /Users/trevord2/.stack/setup-exe-src/setup-mPHDZzAJ.o )
[2 of 2] Compiling StackSetupShim   ( /Users/trevord2/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /Users/trevord2/.stack/setup-exe-src/setup-shim-mPHDZzAJ.o )
Linking /Users/trevord2/.stack/setup-exe-cache/x86_64-osx/tmp-Cabal-simple_mPHDZzAJ_2.0.0.2_ghc-8.2.1 ...
someproj-0.1.0.0: configure (lib + exe)
Configuring someproj-0.1.0.0...
someproj-0.1.0.0: build (lib + exe)
Preprocessing library for someproj-0.1.0.0..
Building library for someproj-0.1.0.0..
[1 of 1] Compiling Lib              ( src/Lib.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/Lib.o )
Preprocessing executable 'someproj-exe' for someproj-0.1.0.0..
Building executable 'someproj-exe' for someproj-0.1.0.0..
[1 of 1] Compiling Main             ( app/Main.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/someproj-exe/someproj-exe-tmp/Main.o )
Linking .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/someproj-exe/someproj-exe ...
someproj-0.1.0.0: copy/register
Installing library in /Users/trevord2/someproj/.stack-work/install/x86_64-osx/nightly-2017-10-13/8.2.1/lib/x86_64-osx-ghc-8.2.1/someproj-0.1.0.0-CipYiGpVvyN2ckNE28vc3U
Installing executable someproj-exe in /Users/trevord2/someproj/.stack-work/install/x86_64-osx/nightly-2017-10-13/8.2.1/bin
BFD: unable to read unknown load command 0x2a
BFD: unable to read unknown load command 0x28
BFD: unable to read unknown load command 0x29
Registering library for someproj-0.1.0.0..

And then I was able to successfully stack build

Doing stack exec someproj-exe results in:
Executable named someproj-exe not found on path: ["/Users/trevord2/someproj/.stack-work/install/x86_64-osx/lts-9.8/8.0.2/bin","/Users/trevord2/.stack/snapshots/x86_64-osx/lts-9.8/8.0.2/bin","/Users/trevord2/.stack/programs/x86_64-osx/ghc-8.0.2/bin","/usr/local/bin","/usr/local/Cellar/postgresql/9.3.5_1/bin","/usr/local/bin","/Users/trevord2/.cabal/bin","/Users/trevord2/.local/bin","/Users/trevord2/Library/Haskell/bin","/usr/bin","/bin","/usr/sbin","/sbin","/opt/X11/bin","/usr/local/opt/fzf/bin"]

And trying to install via stack install hindent --resolver nightly-2017-10-13 resulted in the below

--  While building package cpphs-1.20.8 using:
      /Users/trevord2/.stack/setup-exe-cache/x86_64-osx/Cabal-simple_mPHDZzAJ_2.0.0.2_ghc-8.2.1 --builddir=.stack-work/dist/x86_64-osx/Cabal-2.0.0.2 build --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1
    Logs have been written to: /Users/trevord2/someproj/.stack-work/logs/cpphs-1.20.8.log

    Configuring cpphs-1.20.8...
    Preprocessing library for cpphs-1.20.8..
    Building library for cpphs-1.20.8..
    [ 1 of 11] Compiling Language.Preprocessor.Cpphs.HashDefine ( Language/Preprocessor/Cpphs/HashDefine.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/Language/Preprocessor/Cpphs/HashDefine.o )
    [ 2 of 11] Compiling Language.Preprocessor.Cpphs.Options ( Language/Preprocessor/Cpphs/Options.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/Language/Preprocessor/Cpphs/Options.o )
    [ 3 of 11] Compiling Language.Preprocessor.Cpphs.Position ( Language/Preprocessor/Cpphs/Position.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/Language/Preprocessor/Cpphs/Position.o )
    [ 4 of 11] Compiling Language.Preprocessor.Cpphs.ReadFirst ( Language/Preprocessor/Cpphs/ReadFirst.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/Language/Preprocessor/Cpphs/ReadFirst.o )
    [ 5 of 11] Compiling Language.Preprocessor.Cpphs.SymTab ( Language/Preprocessor/Cpphs/SymTab.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/Language/Preprocessor/Cpphs/SymTab.o )
    [ 6 of 11] Compiling Language.Preprocessor.Cpphs.Tokenise ( Language/Preprocessor/Cpphs/Tokenise.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/Language/Preprocessor/Cpphs/Tokenise.o )
    [ 7 of 11] Compiling Language.Preprocessor.Cpphs.MacroPass ( Language/Preprocessor/Cpphs/MacroPass.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/Language/Preprocessor/Cpphs/MacroPass.o )
    [ 8 of 11] Compiling Language.Preprocessor.Cpphs.CppIfdef ( Language/Preprocessor/Cpphs/CppIfdef.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/Language/Preprocessor/Cpphs/CppIfdef.o )
    [ 9 of 11] Compiling Language.Preprocessor.Unlit ( Language/Preprocessor/Unlit.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/Language/Preprocessor/Unlit.o )
    [10 of 11] Compiling Language.Preprocessor.Cpphs.RunCpphs ( Language/Preprocessor/Cpphs/RunCpphs.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/Language/Preprocessor/Cpphs/RunCpphs.o )
    [11 of 11] Compiling Language.Preprocessor.Cpphs ( Language/Preprocessor/Cpphs.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/Language/Preprocessor/Cpphs.o )
    Preprocessing executable 'cpphs' for cpphs-1.20.8..
    Building executable 'cpphs' for cpphs-1.20.8..
    [ 1 of 12] Compiling Language.Preprocessor.Cpphs.HashDefine ( Language/Preprocessor/Cpphs/HashDefine.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/cpphs/cpphs-tmp/Language/Preprocessor/Cpphs/HashDefine.o )
    [ 2 of 12] Compiling Language.Preprocessor.Cpphs.Options ( Language/Preprocessor/Cpphs/Options.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/cpphs/cpphs-tmp/Language/Preprocessor/Cpphs/Options.o )
    [ 3 of 12] Compiling Language.Preprocessor.Cpphs.Position ( Language/Preprocessor/Cpphs/Position.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/cpphs/cpphs-tmp/Language/Preprocessor/Cpphs/Position.o )
    [ 4 of 12] Compiling Language.Preprocessor.Cpphs.ReadFirst ( Language/Preprocessor/Cpphs/ReadFirst.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/cpphs/cpphs-tmp/Language/Preprocessor/Cpphs/ReadFirst.o )
    [ 5 of 12] Compiling Language.Preprocessor.Cpphs.SymTab ( Language/Preprocessor/Cpphs/SymTab.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/cpphs/cpphs-tmp/Language/Preprocessor/Cpphs/SymTab.o )
    [ 6 of 12] Compiling Language.Preprocessor.Cpphs.Tokenise ( Language/Preprocessor/Cpphs/Tokenise.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/cpphs/cpphs-tmp/Language/Preprocessor/Cpphs/Tokenise.o )
    [ 7 of 12] Compiling Language.Preprocessor.Cpphs.MacroPass ( Language/Preprocessor/Cpphs/MacroPass.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/cpphs/cpphs-tmp/Language/Preprocessor/Cpphs/MacroPass.o )
    [ 8 of 12] Compiling Language.Preprocessor.Cpphs.CppIfdef ( Language/Preprocessor/Cpphs/CppIfdef.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/cpphs/cpphs-tmp/Language/Preprocessor/Cpphs/CppIfdef.o )
    [ 9 of 12] Compiling Language.Preprocessor.Unlit ( Language/Preprocessor/Unlit.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/cpphs/cpphs-tmp/Language/Preprocessor/Unlit.o )
    [10 of 12] Compiling Language.Preprocessor.Cpphs.RunCpphs ( Language/Preprocessor/Cpphs/RunCpphs.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/cpphs/cpphs-tmp/Language/Preprocessor/Cpphs/RunCpphs.o )
    [11 of 12] Compiling Language.Preprocessor.Cpphs ( Language/Preprocessor/Cpphs.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/cpphs/cpphs-tmp/Language/Preprocessor/Cpphs.o )
    [12 of 12] Compiling Main             ( cpphs.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/cpphs/cpphs-tmp/Main.o )
    Linking .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/cpphs/cpphs ...
    ld: warning: ld: warning: ld: warning: ignoring file /Users/trevord2/.stack/snapshots/x86_64-osx/nightly-2017-10-13/8.2.1/lib/x86_64-osx-ghc-8.2.1/text-1.2.2.2-Ja5vhWvrB3PHMSPwq0buEf/libHStext-1.2.2.2-Ja5vhWvrB3PHMSPwq0buEf.a, file was built for archive which is not the architecture being linked (x86_64): /Users/trevord2/.stack/snapshots/x86_64-osx/nightly-2017-10-13/8.2.1/lib/x86_64-osx-ghc-8.2.1/text-1.2.2.2-Ja5vhWvrB3PHMSPwq0buEf/libHStext-1.2.2.2-Ja5vhWvrB3PHMSPwq0buEf.aignoring file /Users/trevord2/.stack/snapshots/x86_64-osx/nightly-2017-10-13/8.2.1/lib/x86_64-osx-ghc-8.2.1/polyparse-1.12-AVTJB7uViYAKVv5K5Mtfxn/libHSpolyparse-1.12-AVTJB7uViYAKVv5K5Mtfxn.a, file was built for archive which is not the architecture being linked (x86_64): /Users/trevord2/.stack/snapshots/x86_64-osx/nightly-2017-10-13/8.2.1/lib/x86_64-osx-ghc-8.2.1/polyparse-1.12-AVTJB7uViYAKVv5K5Mtfxn/libHSpolyparse-1.12-AVTJB7uViYAKVv5K5Mtfxn.aignoring file /Users/trevord2/.stack/snapshots/x86_64-osx/nightly-2017-10-13/8.2.1/lib/x86_64-osx-ghc-8.2.1/old-locale-1.0.0.7-1sqf81TERjR1yVX7sI2OtM/libHSold-locale-1.0.0.7-1sqf81TERjR1yVX7sI2OtM.a, file was built for archive which is not the architecture being linked (x86_64): /Users/trevord2/.stack/snapshots/x86_64-osx/nightly-2017-10-13/8.2.1/lib/x86_64-osx-ghc-8.2.1/old-locale-1.0.0.7-1sqf81TERjR1yVX7sI2OtM/libHSold-locale-1.0.0.7-1sqf81TERjR1yVX7sI2OtM.a


    Undefined symbols for architecture x86_64:
      "_polyparsezm1zi12zmAVTJB7uViYAKVv5K5Mtfxn_TextziParserCombinatorsziPolyziBase_many1_closure", referenced from:
          _SufA_srt in CppIfdef.o
          _SuY9_srt in CppIfdef.o
          _Sv0P_srt in CppIfdef.o
      "_polyparsezm1zi12zmAVTJB7uViYAKVv5K5Mtfxn_TextziParse_zddmparseList1_closure", referenced from:
          _Su9V_srt in CppIfdef.o
          _SuiM_srt in CppIfdef.o
          _Suqo_srt in CppIfdef.o
          _SuCr_srt in CppIfdef.o
          _SuDg_srt in CppIfdef.o
          _SuE5_srt in CppIfdef.o
          _SuJL_srt in CppIfdef.o
          ...
      "_polyparsezm1zi12zmAVTJB7uViYAKVv5K5Mtfxn_TextziParserCombinatorsziPolyziParser_eof2_closure", referenced from:
          _rtyO_info in CppIfdef.o
          _SvkV_srt in CppIfdef.o
      "_polyparsezm1zi12zmAVTJB7uViYAKVv5K5Mtfxn_TextziParserCombinatorsziPolyziParser_eof4_closure", referenced from:
          _rtyI_info in CppIfdef.o
      "_polyparsezm1zi12zmAVTJB7uViYAKVv5K5Mtfxn_TextziParserCombinatorsziPolyziParser_satisfy1_closure", referenced from:
          _SuaC_srt in CppIfdef.o
          _Sufm_srt in CppIfdef.o
          _SuXV_srt in CppIfdef.o
          _Sv0B_srt in CppIfdef.o
      "_polyparsezm1zi12zmAVTJB7uViYAKVv5K5Mtfxn_TextziParserCombinatorsziPolyziResult_zdwresultToEither_info", referenced from:
          _cump_info in CppIfdef.o
          _cum3_info in CppIfdef.o
          _cusM_info in CppIfdef.o
          _cv8c_info in CppIfdef.o
          _cw2M_info in CppIfdef.o
          _cw2n_info in CppIfdef.o
      "_polyparsezm1zi12zmAVTJB7uViYAKVv5K5Mtfxn_TextziParserCombinatorsziPolyziBase_sepBy1_info", referenced from:
          _stCb_info in CppIfdef.o
          _rtyw_info in CppIfdef.o
      "_polyparsezm1zi12zmAVTJB7uViYAKVv5K5Mtfxn_TextziParserCombinatorsziPolyziResult_Failure_con_info", referenced from:
          _cug6_info in CppIfdef.o
          _cv8l_info in CppIfdef.o
          _rtyO_info in CppIfdef.o
      "_polyparsezm1zi12zmAVTJB7uViYAKVv5K5Mtfxn_TextziParserCombinatorsziPolyziBase_sepBy1_closure", referenced from:
          _Suqo_srt in CppIfdef.o
          _SuYq_srt in CppIfdef.o
      "_polyparsezm1zi12zmAVTJB7uViYAKVv5K5Mtfxn_TextziParserCombinatorsziPolyziParser_zdfAlternativeParser2_info", referenced from:
          _rtxk_info in CppIfdef.o
          _stJb_info in CppIfdef.o
          _stJk_info in CppIfdef.o
          _rtzf_info in CppIfdef.o
          _rtzk_info in CppIfdef.o
      "_polyparsezm1zi12zmAVTJB7uViYAKVv5K5Mtfxn_TextziParserCombinatorsziPolyziResult_zdfFunctorResultzuzdcfmap_info", referenced from:
          _cuau_info in CppIfdef.o
          _cuFj_info in CppIfdef.o
          _stJA_info in CppIfdef.o
          _cv8l_info in CppIfdef.o
          _cvLU_info in CppIfdef.o
          _cvPz_info in CppIfdef.o
      "_polyparsezm1zi12zmAVTJB7uViYAKVv5K5Mtfxn_TextziParserCombinatorsziPolyziBase_many1_info", referenced from:
          _rtxL_info in CppIfdef.o
          _rtyv_info in CppIfdef.o
          _rtyH_info in CppIfdef.o
      "_oldzmlocalezm1zi0zi0zi7zm1sqf81TERjR1yVX7sI2OtM_SystemziLocale_defaultTimeLocale_closure", referenced from:
          _soxj_info in MacroPass.o
          _soy7_info in MacroPass.o
          _Sp18_srt in MacroPass.o
      "_polyparsezm1zi12zmAVTJB7uViYAKVv5K5Mtfxn_TextziParserCombinatorsziPolyziParser_satisfy1_info", referenced from:
          _rtxj_info in CppIfdef.o
          _rtxK_info in CppIfdef.o
          _rtyu_info in CppIfdef.o
          _rtyG_info in CppIfdef.o
      "_polyparsezm1zi12zmAVTJB7uViYAKVv5K5Mtfxn_TextziParserCombinatorsziPolyziResult_Committed_con_info", referenced from:
          _cu8W_info in CppIfdef.o
          _cu8M_info in CppIfdef.o
          _cug6_info in CppIfdef.o
          _cuih_info in CppIfdef.o
          _cujI_info in CppIfdef.o
          _cukx_info in CppIfdef.o
          _cun5_info in CppIfdef.o
          ...
      "_polyparsezm1zi12zmAVTJB7uViYAKVv5K5Mtfxn_TextziParserCombinatorsziPolyziParser_zdfCommitmentParser3_info", referenced from:
          _cune_info in CppIfdef.o
          _cv56_info in CppIfdef.o
          _cv78_info in CppIfdef.o
          _cvL6_info in CppIfdef.o
          _cvQ0_info in CppIfdef.o
          _cvTa_info in CppIfdef.o
          _cvVm_info in CppIfdef.o
          ...
      "_polyparsezm1zi12zmAVTJB7uViYAKVv5K5Mtfxn_TextziParserCombinatorsziPolyziParser_zdfPolyParseParser_closure", referenced from:
          _rtxL_info in CppIfdef.o
          _stCb_info in CppIfdef.o
          _rtyv_info in CppIfdef.o
          _rtyw_info in CppIfdef.o
          _rtyH_info in CppIfdef.o
          _SufA_srt in CppIfdef.o
          _Suqo_srt in CppIfdef.o
          ...
      "_polyparsezm1zi12zmAVTJB7uViYAKVv5K5Mtfxn_TextziParse_zddmparseList1_info", referenced from:
          _cu8M_info in CppIfdef.o
          _cuih_info in CppIfdef.o
          _cunY_info in CppIfdef.o
          _cuBW_info in CppIfdef.o
          _cuCL_info in CppIfdef.o
          _cuDA_info in CppIfdef.o
          _cuFv_info in CppIfdef.o
          ...
      "_polyparsezm1zi12zmAVTJB7uViYAKVv5K5Mtfxn_TextziParserCombinatorsziPolyziResult_Success_con_info", referenced from:
          _cu8W_info in CppIfdef.o
          _cuaN_info in CppIfdef.o
          _cuhq_info in CppIfdef.o
          _cune_info in CppIfdef.o
          _cuo8_info in CppIfdef.o
          _cupp_info in CppIfdef.o
          _cuze_info in CppIfdef.o
          ...
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    `gcc' failed in phase `Linker'. (Exit code: 1)

@snoyberg
Copy link
Contributor

Alright, let's next see if the problem occurs with GHC outside of a project. Can you create a Hello World-style Haskell file (main = return ()) and then run:

stack --resolver ghc-8.2.1 exec -- ghc Main.hs

It would also be informative if compiling a C file produces any errors.

One thing I'm afraid of here: this looks more likely to be an issue at the GHC layer than either the Cabal or Stack layers, so we may not be able to do much to help you.

@snoyberg
Copy link
Contributor

A quick Google of the error message also indicates this may be a configuration error with your C toolchain, where you have some 32-bit libraries installed.

@td-ideabox
Copy link
Author

It appears that things built correctly using the command you mentioned above:

 λ ~/ stack --resolver ghc-8.2.1 exec -- ghc Main.hs

[1 of 1] Compiling Main             ( Main.hs, Main.o )
Linking Main ...
λ ~/ ./Main
Hello, World
λ ~/
λ ~/
λ ~/
λ ~/ tail Main.hs
module Main where
main = putStrLn "Hello, World"

And compiling a C file:

λ ~/ tail main.c
/* Hello World program */

#include<stdio.h>

int main()
{
 printf("Hello World");
 return 0;
}
λ ~/ gcc main.c -o main.o
λ ~/ ./main.o
Hello World%

gcc info:

λ ~/ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.37)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

@snoyberg
Copy link
Contributor

Interesting. Can you try running the following two commands as well?

$ stack exec --no-ghc-package-path -- runghc Setup.hs configure --user --verbose
$ stack exec --no-ghc-package-path -- runghc Setup.hs build --verbose

@td-ideabox
Copy link
Author

td-ideabox commented Oct 17, 2017

Run inside of the project someproj that we've been using.
First command:


Configuring someproj-0.1.0.0...
Dependency base >=4.7 && <5: using base-4.9.1.0
Dependency someproj -any: using someproj-0.1.0.0
Warning: cannot determine version of
/Users/trevord2/.stack/snapshots/x86_64-osx/lts-9.8/8.0.2/bin/happy :
""
Using Cabal-1.24.2.0 compiled by ghc-8.0
Using compiler: ghc-8.0.2
Using install prefix: /Users/trevord2/.cabal
Binaries installed in: /Users/trevord2/.cabal/bin
Libraries installed in:
/Users/trevord2/.cabal/lib/x86_64-osx-ghc-8.0.2/someproj-0.1.0.0-6corWoTDCA69pE1sqNF8Id
Dynamic libraries installed in:
/Users/trevord2/.cabal/lib/x86_64-osx-ghc-8.0.2
Private binaries installed in: /Users/trevord2/.cabal/libexec
Data files installed in:
/Users/trevord2/.cabal/share/x86_64-osx-ghc-8.0.2/someproj-0.1.0.0
Documentation installed in:
/Users/trevord2/.cabal/share/doc/x86_64-osx-ghc-8.0.2/someproj-0.1.0.0
Configuration files installed in: /Users/trevord2/.cabal/etc
Using alex version 3.2.1 found on system at: /usr/local/bin/alex
Using ar found on system at: /usr/local/bin/ar
No c2hs found
No cpphs found
Using gcc version 4.2.1 found on system at: /usr/bin/gcc
Using ghc version 8.0.2 found on system at:
/Users/trevord2/.stack/programs/x86_64-osx/ghc-8.0.2/bin/ghc
Using ghc-pkg version 8.0.2 found on system at:
/Users/trevord2/.stack/programs/x86_64-osx/ghc-8.0.2/bin/ghc-pkg
No ghcjs found
No ghcjs-pkg found
No greencard found
Using haddock version 2.17.3 found on system at:
/Users/trevord2/.stack/programs/x86_64-osx/ghc-8.0.2/bin/haddock
Using happy found on system at:
/Users/trevord2/.stack/snapshots/x86_64-osx/lts-9.8/8.0.2/bin/happy
Using haskell-suite found on system at: haskell-suite-dummy-location
Using haskell-suite-pkg found on system at: haskell-suite-pkg-dummy-location
No hmake found
Using hpc version 0.67 found on system at:
/Users/trevord2/.stack/programs/x86_64-osx/ghc-8.0.2/bin/hpc
Using hsc2hs version 0.68.1 found on system at:
/Users/trevord2/.stack/programs/x86_64-osx/ghc-8.0.2/bin/hsc2hs
Using hscolour version 1.24 found on system at: /usr/local/bin/HsColour
No jhc found
Using ld found on system at: /usr/bin/ld
No lhc found
No lhc-pkg found
Using pkg-config version 0.29.2 found on system at: /usr/local/bin/pkg-config
Using strip version 2.22 found on system at: /usr/local/bin/strip
Using tar found on system at: /usr/bin/tar
No uhc found

Second command:

λ ~/someproj/ stack exec --no-ghc-package-path -- runghc Setup.hs build --verbose
Component build order: library, executable 'someproj-exe'
creating dist/build
creating dist/build/autogen
Building someproj-0.1.0.0...
/Users/trevord2/.stack/programs/x86_64-osx/ghc-8.0.2/bin/ghc-pkg init dist/package.conf.inplace
Preprocessing library someproj-0.1.0.0...
Building library...
creating dist/build
/Users/trevord2/.stack/programs/x86_64-osx/ghc-8.0.2/bin/ghc --make -fbuilding-cabal-package -O -static -dynamic-too -dynosuf dyn_o -dynhisuf dyn_hi -outputdir dist/build -odir dist/build -hidir dist/build -stubdir dist/build -i -idist/build -isrc -idist/build/autogen -Idist/build/autogen -Idist/build -optP-include -optPdist/build/autogen/cabal_macros.h -this-unit-id someproj-0.1.0.0-6corWoTDCA69pE1sqNF8Id -hide-all-packages -package-db dist/package.conf.inplace -package-id base-4.9.1.0 -XHaskell2010 Lib
[1 of 1] Compiling Lib              ( src/Lib.hs, dist/build/Lib.o )
Linking...
[(SimpleUnitId (ComponentId "base-4.9.1.0"),PackageIdentifier {pkgName =
PackageName {unPackageName = "base"}, pkgVersion = Version {versionBranch =
[4,9,1,0], versionTags = []}},ModuleRenaming True [])]
/usr/local/bin/ar -r -s dist/build/objs-23343/libHSsomeproj-0.1.0.0-6corWoTDCA69pE1sqNF8Id.a dist/build/Lib.o
/usr/local/bin/ar: creating dist/build/objs-23343/libHSsomeproj-0.1.0.0-6corWoTDCA69pE1sqNF8Id.a
/Users/trevord2/.stack/programs/x86_64-osx/ghc-8.0.2/bin/ghc -shared -dynamic '-dynload deploy' -optl-Wl,-rpath,/Users/trevord2/.stack/programs/x86_64-osx/ghc-8.0.2/lib/ghc-8.0.2/base-4.9.1.0 -optl-Wl,-rpath,/Users/trevord2/.stack/programs/x86_64-osx/ghc-8.0.2/lib/ghc-8.0.2/ghc-prim-0.5.0.0 -optl-Wl,-rpath,/Users/trevord2/.stack/programs/x86_64-osx/ghc-8.0.2/lib/ghc-8.0.2/integer-gmp-1.0.0.1 -optl-Wl,-rpath,/Users/trevord2/.stack/programs/x86_64-osx/ghc-8.0.2/lib/ghc-8.0.2/rts -hide-all-packages -no-auto-link-packages -package-db dist/package.conf.inplace -package-id base-4.9.1.0 dist/build/Lib.dyn_o -o dist/build/libHSsomeproj-0.1.0.0-6corWoTDCA69pE1sqNF8Id-ghc8.0.2.dylib
/Users/trevord2/.stack/programs/x86_64-osx/ghc-8.0.2/bin/ghc-pkg update - --global --user '--package-db=dist/package.conf.inplace'
Preprocessing executable 'someproj-exe' for someproj-0.1.0.0...
Building executable someproj-exe...
creating dist/build/someproj-exe
creating dist/build/someproj-exe/someproj-exe-tmp
/Users/trevord2/.stack/programs/x86_64-osx/ghc-8.0.2/bin/ghc --make -no-link -fbuilding-cabal-package -O -static -outputdir dist/build/someproj-exe/someproj-exe-tmp -odir dist/build/someproj-exe/someproj-exe-tmp -hidir dist/build/someproj-exe/someproj-exe-tmp -stubdir dist/build/someproj-exe/someproj-exe-tmp -i -idist/build/someproj-exe/someproj-exe-tmp -iapp -idist/build/autogen -Idist/build/autogen -Idist/build/someproj-exe/someproj-exe-tmp -optP-include -optPdist/build/autogen/cabal_macros.h -hide-all-packages -package-db dist/package.conf.inplace -package-id base-4.9.1.0 -package-id someproj-0.1.0.0-6corWoTDCA69pE1sqNF8Id -XHaskell2010 app/Main.hs -threaded -rtsopts '-with-rtsopts=-N'
[1 of 1] Compiling Main             ( app/Main.hs, dist/build/someproj-exe/someproj-exe-tmp/Main.o )
Linking...
/Users/trevord2/.stack/programs/x86_64-osx/ghc-8.0.2/bin/ghc --make -fbuilding-cabal-package -O -static -outputdir dist/build/someproj-exe/someproj-exe-tmp -odir dist/build/someproj-exe/someproj-exe-tmp -hidir dist/build/someproj-exe/someproj-exe-tmp -stubdir dist/build/someproj-exe/someproj-exe-tmp -i -idist/build/someproj-exe/someproj-exe-tmp -iapp -idist/build/autogen -Idist/build/autogen -Idist/build/someproj-exe/someproj-exe-tmp -optP-include -optPdist/build/autogen/cabal_macros.h -hide-all-packages -package-db dist/package.conf.inplace -package-id base-4.9.1.0 -package-id someproj-0.1.0.0-6corWoTDCA69pE1sqNF8Id -XHaskell2010 app/Main.hs -o dist/build/someproj-exe/someproj-exe -threaded -rtsopts '-with-rtsopts=-N'
Linking dist/build/someproj-exe/someproj-exe ...
ld: warning: ignoring file /Users/trevord2/someproj/dist/build/libHSsomeproj-0.1.0.0-6corWoTDCA69pE1sqNF8Id.a, file was built for archive which is not the architecture being linked (x86_64): /Users/trevord2/someproj/dist/build/libHSsomeproj-0.1.0.0-6corWoTDCA69pE1sqNF8Id.a
Undefined symbols for architecture x86_64:
  "_someprojzm0zi1zi0zi0zm6corWoTDCA69pE1sqNF8Id_Lib_someFunc1_closure", referenced from:
      _Main_main1_info in Main.o
      _S39Z_srt in Main.o
  "_someprojzm0zi1zi0zi0zm6corWoTDCA69pE1sqNF8Id_Lib_someFunc1_info", referenced from:
      _Main_main_info in Main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`gcc' failed in phase `Linker'. (Exit code: 1)

@trevordilley
Copy link

Potentially related?

#2712

@snoyberg
Copy link
Contributor

I'm starting to run out of ideas. The biggest difference I see between the raw GHC invocation that worked above and the invocation that Cabal is making is that the latter is doing a static compilation. What happens if you compile with:

stack --resolver ghc-8.2.1 exec -- ghc Main.hs -static

@td-ideabox
Copy link
Author

So I should run this on a "Hello, world" Main.hs? Here's the output on that:

λ ~/ stack --resolver ghc-8.2.1 exec -- ghc Main.hs -static
Linking Main ...
ld: can't link with a main executable file 'Main.o' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`gcc' failed in phase `Linker'. (Exit code: 1)

@snoyberg
Copy link
Contributor

Looks like we have a winner: GHC is unable to do static linking. Why that's the case, however, I don't know. Adding a -v to the end of that command line will give more info on how GCC/Clang was called.

@nkaretnikov
Copy link
Contributor

Just bumped into this while trying to build cpphs-1.20.8 (reproduced multiple times). Tried cleaning both global and local stack directories, no dice.

@nkaretnikov
Copy link
Contributor

FWIW, the project I was trying to build is https://github.com/Lemmih/lhc
There are build instructions in the readme file.

@nkaretnikov
Copy link
Contributor

nkaretnikov commented Apr 12, 2018

Spent a bit of time on this. Specifically, tried building cpphs-1.20.8 with stack and cabal (inside nix-shell) from source. The former fails, the latter succeeds.

stack unpack ...
stack init
stack build
# vs.
cabal2nix --shell . > shell.nix
nix-shell
cabal build

So it's likely to either be a difference in library versions or flags (or maybe something else).

@nkaretnikov
Copy link
Contributor

Okay, I think i've figured it out. I also had ghc installed globally via brew. So I removed /usr/local/bin from PATH and tried again:

rm -rf ~/.stack
stack init --force
stack build 

This forced ghc to be downloaded and cpphs was successfully built.

@snoyberg, could you confirm that this might be the cause?

@snoyberg
Copy link
Contributor

It looks like you took a few different actions, and one of them fixed the problem. They all seem to point at a root cause of a different version of GHC already being installed, and forcing a new installation, which seems reasonable to me.

@soulomoon
Copy link

same problem here, I prepend /usr/bin in front of /usr/local/bin in the path , then it works
It seems there are some name-duplicate executables behave differently between /usr/bin and /usr/local/bin

@dbaynard
Copy link
Contributor

I think #4366 resolves this (there's a workaround). @soulomoon would you confirm, please, and then close if it does?

@soulomoon
Copy link

soulomoon commented Oct 31, 2018

I don't have llvm installed so no for #4366, but the reason is similar, /usr/local/bin is where my brew install most of the binaries, so it might be binaries there have the same names as those in /usr/bin. But I have not not pinpoint the exact binaries yet.

@soulomoon
Copy link

soulomoon commented Oct 31, 2018

/usr/local/bin/ar  -> ../Cellar/binutils/2.31.1_1/bin/ar
/usr/local/bin/strip -> ../Cellar/binutils/2.31.1_1/bin/strip

these are the two binaries stop me @dbaynard and they are from binutils package I installed from brew.
I guess it is mostly because the gnu tool set have a different parameters standard from Darwin's

@laishulu
Copy link

laishulu commented Nov 15, 2018

@soulomoon I failed to run stack install cpphs in macos, I also have binutils installed.
But when I prepend /usr/bin in PATH, I got:

    [11 of 11] Compiling Language.Preprocessor.Cpphs ( Language/Preprocessor/Cpphs.hs, .stack-work/dist/x86_64-osx/Cabal-2.2.0.1/build/Language/Preprocessor/Cpphs.o )
    ar: @.stack-work/dist/x86_64-osx/Cabal-2.2.0.1/build/objs-78530/ar78530-2.rsp: No such file or directory

@nh2
Copy link
Collaborator

nh2 commented Nov 20, 2018

Perhaps a previous build was aborted and left .o files half-written on disk?

#14533 - Make GHC more robust against PC crashes by using atomic writes

In general, when we get issues like this, we should try to look at the object file where the symbols should come from and see if they are cut off.

@pwm
Copy link

pwm commented Jun 14, 2019

This happened to me and it was indeed binutils, more specifically the one homebrew installed. Once I uninstalled the homebrew one everything worked.

@ta3pks
Copy link

ta3pks commented Jun 16, 2019

@pwm how did you get everything working after you removed the binutils. I tried doing the same but the build now fails complaining it cannot find ar

@ta3pks
Copy link

ta3pks commented Jun 16, 2019

i fixed the ar problem now by creating a new project but still it wont compile on mac

@RyotaBannai
Copy link

RyotaBannai commented Jul 26, 2021

@NikosEfthias
+1 same here.

@vjeranc
Copy link

vjeranc commented Aug 28, 2021

I've managed to successfully build hakyll on MacOS Big Sur 11.5.2 with stack by removing brew binutils. I've also been having Undefined symbols errors.

@mpilgrem
Copy link
Member

I am closing given the passage of time.

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

No branches or pull requests