Linux command
ghc 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Compile a Haskell file
ghc [file.hs]
Compile with optimization
ghc -O2 [file.hs]
Compile to object file only
ghc -c [file.hs]
Specify output name
ghc -o [program] [file.hs]
Enable all warnings
ghc -Wall [file.hs]
Compile modules in parallel
ghc -j [file.hs]
Enable a language extension
ghc -XOverloadedStrings [file.hs]
说明
ghc (Glasgow Haskell Compiler) is the leading compiler for the Haskell programming language. It compiles Haskell source code to native machine code, producing efficient executables. GHC supports the full Haskell language standard plus numerous extensions for advanced type system features, parallelism, and performance. The --make mode (default) automatically handles module dependencies. GHC also provides native code generation and an optional LLVM backend.
参数
- -o _FILE_
- Output file name.
- -c
- Compile to object file only.
- -O, -O1
- Enable standard optimization.
- -O2
- Enable aggressive optimization with additional passes.
- -O0
- Disable optimization (default).
- -Wall
- Enable most warnings.
- -w
- Suppress all warnings.
- -Werror
- Treat warnings as errors.
- -i_DIR_
- Add directory to import search path.
- -package _PKG_
- Expose the specified package.
- --make
- Build program and resolve module dependencies automatically.
- -e _EXPR_
- Evaluate a single expression and exit.
- -j_N_
- Compile N modules in parallel.
- -threaded
- Use the threaded runtime system.
- -prof
- Enable profiling.
- -fllvm
- Compile via LLVM backend.
- -X_EXTENSION_
- Enable a language extension (e.g., -XOverloadedStrings).
- -cpp
- Run the C preprocessor on source files.
- -v_N_
- Set verbosity level (0-3).
- --help
- Display help information.
FAQ
What is the ghc command used for?
ghc (Glasgow Haskell Compiler) is the leading compiler for the Haskell programming language. It compiles Haskell source code to native machine code, producing efficient executables. GHC supports the full Haskell language standard plus numerous extensions for advanced type system features, parallelism, and performance. The --make mode (default) automatically handles module dependencies. GHC also provides native code generation and an optional LLVM backend.
How do I run a basic ghc example?
Run `ghc [file.hs]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -o _FILE_ do in ghc?
Output file name.