LoginSignup
5
3

More than 5 years have passed since last update.

Haskell でコンパイル時、 clang がエラーを吐いて失敗するときの対処法

Last updated at Posted at 2018-09-28

背景

すごいH本(すごいHaskell楽しく学ぼう!) の 8.2 Hello, World! で .hs ファイルをコンパイルする説明があるが、実際にやってみたらエラーになって困った。

問題

$ cat helloworld.hs
main = putStrLn "hello, world"

というようにファイルを用意した状態で、以下のコマンドを打つと、エラーになる。

$ ghc --make hello
[1 of 1] Compiling Main             ( hello.hs, hello.o )
clang: error: unknown argument: '-no-pie'
`gcc' failed in phase `Assembler'. (Exit code: 1)

対策

まず root 権限になる。

$ sudo su - root

次に、/Library/Frameworks/GHC.framework/Versions/8.4.3-x86_64/usr/lib/ghc-8.4.3/settings ファイルをいじる。

$ vim /Library/Frameworks/GHC.framework/Versions/8.4.3-x86_64/usr/lib/ghc-8.4.3/settings

以下のように変更する

before
...省略...
, ("C compiler supports -no-pie","YES")
...省略...
after
...省略...
, ("C compiler supports -no-pie","NO")
...省略...

gcc/ghc のバージョン

gcc のバージョンは、

$ gcc -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

ghc のバージョンは、

$ghc -v
Glasgow Haskell Compiler, Version 8.4.3, stage 2 booted by GHC version 8.2.2
Using binary package database: /Library/Frameworks/GHC.framework/Versions/8.4.3-x86_64/usr/lib/ghc-8.4.3/package.conf.d/package.cache
package flags []
loading package database /Library/Frameworks/GHC.framework/Versions/8.4.3-x86_64/usr/lib/ghc-8.4.3/package.conf.d
wired-in package ghc-prim mapped to ghc-prim-0.5.2.0
wired-in package integer-gmp mapped to integer-gmp-1.0.2.0
wired-in package base mapped to base-4.11.1.0
wired-in package rts mapped to rts
wired-in package template-haskell mapped to template-haskell-2.13.0.0
wired-in package ghc mapped to ghc-8.4.3
wired-in package dph-seq not found.
wired-in package dph-par not found.
*** Deleting temp files:
Deleting:
*** Deleting temp dirs:
Deleting:
ghc: no input files
Usage: For basic information, try the `--help' option.

参考

こちらを参考にした。
https://stackoverflow.com/questions/50386787/cabal-install-gcc-failed-in-phase-c-compiler/50419101#50419101

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3