Closed notfirefox closed 1 day ago
Does doing brew install gcc@11
help?
@carlocab
It does, but gcc@11
is not listed as a hard requirement for ghc
as of right now, right? So one might want to consider adding gcc@11
as a dependency to the ghc
package.
But I'm questioning whether ghc
depends on gcc@11
or just on gcc
in general. There is
a settings file for GHC where the C and C++ compiler is specified (shortened for brevity):
$ cat /home/linuxbrew/.linuxbrew/Cellar/ghc/9.10.1/lib/ghc-9.10.1/lib/settings
[("C compiler command", "gcc-11")
,("C compiler flags", "")
,("C++ compiler command", "g++-11")
,("C++ compiler flags", "")
...
]
I am bringing this up, because the Homebrew documentation recommends installing build tools on the Linux host system, i.e. the following packages on Ubuntu/Debian:
sudo apt-get install build-essential procps curl file git
Same goes for Fedora, CentOS, or Red Hat and Arch Linux, so most likely gcc
is installed on the Linux host system.
Therefore I was wondering if it might make sense for the ghc
formula to configure ghc
in a way that it looks for gcc
instead of gcc-11
on Linux x86.
Therefore I was wondering if it might make sense for the
ghc
formula to configureghc
in a way that it looks forgcc
instead ofgcc-11
on Linux x86.
Yes, probably. My question was just to check that you had a quick workaround for now. A proper fix may take a bit, but PRs are welcome.
Probably better to avoid hardcoding a particular C compiler at all. Might help to modify this line
to point to just "cc"
or something.
Fixed in #183926.
Do brew update && brew reinstall ghc
in about ~15 minutes.
That indeed fixed the issue. There are a few questions remaining however.
In my previous message I have mentioned the /home/linuxbrew/.linuxbrew/Cellar/ghc/9.10.1/lib/ghc-9.10.1/lib/settings
file. After the fix the file looks like shown below (shortened for brevity):
$ cat /home/linuxbrew/.linuxbrew/Cellar/ghc/9.10.1/lib/ghc-9.10.1/lib/settings
[("C compiler command", "cc")
,("C compiler flags", "")
,("C++ compiler command", "g++-11")
,("C++ compiler flags", "")
...
]
As you can see the C compiler command
now is set to cc
which is good. The C++ compiler command
is set to g++-11
which might not be good. I am not sure if and how GHC uses the C++ compiler command
but one might want to consider setting the CXX
and ac_cv_path_CXX
environment variable to "c++"
on Linux, e.g. something like this:
ENV["CXX"] = ENV["ac_cv_path_CXX"] = OS.linux? ? "c++" : ENV.cxx
Then there would be the question on what to do about the other versions of GHC. There are in total five other versions, three of those are not deprecated or disabled. Maybe it could make sense to apply the same fix to those versions as well?
ghc@9.8
ghc@9.6
ghc@9.4
ghc@9.2
(deprecated)ghc@8.10
(disabled)I wonder if, instead of setting CC
and CXX
, we should just be modifying
lib/ghc-9.10.1/lib/settings
at install-time? This way we can use gcc-11
and g++-11
if available, and then fall back to something else if not.
This way we try to ensure we're using a compiler compatible with the one that ghc
was built with where available. Using a different one likely doesn't hurt, but I'd rather avoid the risk if possible.
I wonder if, instead of setting CC and CXX, we should just be modifying
lib/ghc-9.10.1/lib/settings
at install-time? This way we can use gcc-11 and g++-11 if available, and then fall back to something else if not.
I'm not sure if that is a good idea. I have taken some time to think about it and came up with two concerns.
For one the permissions of the file are set to read-only:
$ ls -l settings
-r--r--r--. 1 notfirefox notfirefox 1687 May 10 07:18 settings
Besides that there is also the possibility that this could break in certain scenarios. Consider the following:
An user installs ghc 9.10.1
on Ubuntu 22.04. This system ships with gcc
version 11, so the exact same version that ghc 9.10.1
got compiled with, so brew
modifies lib/settings
at install-time, so that C compiler command
and C++ compiler command
are set to gcc-11
and g++-11
. If the user now upgrades to Ubuntu 24.04 the gcc
compiler gets updated to version 13. ghc
tries to access gcc-11
which is not available anymore and fails.
I found a use case for ghc
making use of a C++ compiler using C++ compiler command
. The example below currently breaks on Arch Linux, Fedora and Ubuntu 24.04 due to the ghc
compiler looking for a g++-11
binary.
example.cpp
#include <iostream>
extern "C" {
void cppFunction() { std::cout << "Hello from C++!" << std::endl; }
}
Main.hs
{-# LANGUAGE ForeignFunctionInterface #-}
module Main where
import Foreign
import Foreign.C.Types
foreign import ccall "cppFunction" cppFunction :: IO ()
main = do
cppFunction
One should be able to compile the program using the command shown below. This currently fails as explained above.
$ ghc Main.hs example.cpp -o main -lstdc++
ghc-9.10.1: could not execute: g++-11
brew gist-logs <formula>
link ORbrew config
ANDbrew doctor
outputVerification
brew doctor
output saysYour system is ready to brew.
and am still able to reproduce my issue.brew update
and am still able to reproduce my issue.brew doctor
and that did not fix my problem.What were you trying to do (and why)?
Tried to install
ghc
on Ubuntu 24.04 LTS and compile simple Haskell program.What happened (include all command output)?
The Haskell compiler was not able to compile the program.
Main.hs
file:Compile the program:
What did you expect to happen?
The GHC compiler compiles the file.
Step-by-step reproduction instructions (by running
brew
commands)