Brew install boost with GNU gcc compiler (instead of clang)

I am looking for a way to build boost, boost-python, boost-mpi and boost-build using homebrew so that they all use GNU gcc compiler, but not the Apple’s clang compiler.
I tried:
brew install boost --cc=gcc-9, (gcc-9 was built using homebrew: brew install gcc)
which gave a Warning: You passed --cc=gcc-9. Ultimately, this did not quite work.

Does anyone have a working formula to install boost, boost-python, boost-mpi and boost-build such that boost is forced to use GNU gcc compiler, instead of a default clang compiler?

Thanks for any help!

“Did not quite work” says nothing useful. What exactly was printed after that warning? For instance, if you’d seen something like this:

Error: An exception occurred within a child process:
RuntimeError: The requested Homebrew GCC was not installed. You must:
brew install gcc@8

it already tells you how to resolve your problem.

Thanks for your input. That is not the error I get. I already have gcc-9 installed, as I stated in my original post.

The error I get when using brew install --cc= gcc-9 boost is the following:

Last 15 lines from /Users/amritpoudel/Library/Logs/Homebrew/boost/02.b2:

  • rule clang.init-cxxstd-flags ( toolset : condition * : version )

  • called with: ( clang-darwin : clang : )

  • missing argument version

/private/tmp/boost-20200223-52128-mk9chh/boost_1_72_0/tools/build/src/tools/clang.jam:54:see definition of rule ‘clang.init-cxxstd-flags’ being called

/private/tmp/boost-20200223-52128-mk9chh/boost_1_72_0/tools/build/src/build/toolset.jam:44: in toolset.using

/private/tmp/boost-20200223-52128-mk9chh/boost_1_72_0/tools/build/src/tools/clang.jam:28: in clang.init

/private/tmp/boost-20200223-52128-mk9chh/boost_1_72_0/tools/build/src/build/toolset.jam:44: in toolset.using

/private/tmp/boost-20200223-52128-mk9chh/boost_1_72_0/tools/build/src/build/project.jam:1104: in using

project-config.jam:12: in modules.load

/private/tmp/boost-20200223-52128-mk9chh/boost_1_72_0/tools/build/src/build-system.jam:255: in load-config

/private/tmp/boost-20200223-52128-mk9chh/boost_1_72_0/tools/build/src/build-system.jam:486: in load-configuration-files

/private/tmp/boost-20200223-52128-mk9chh/boost_1_72_0/tools/build/src/build-system.jam:607: in load

/private/tmp/boost-20200223-52128-mk9chh/boost_1_72_0/tools/build/src/kernel/modules.jam:295: in import

/private/tmp/boost-20200223-52128-mk9chh/boost_1_72_0/tools/build/src/kernel/bootstrap.jam:139: in boost-build

/private/tmp/boost-20200223-52128-mk9chh/boost_1_72_0/boost-build.jam:17: in module scope

Try dumping the failed build logs with brew gist-logs boost, and post the gist link here.

Here is the link to the log:

Thanks!

Sorry, I can confirm that I can’t build Boost from source with any version of Homebrew GCC, but I don’t use Boost in my programs, so that’s as far as I can go with this.

Does anyone here know how to install boost with homebrew built gcc?

Homebrew is a package manager. I don’t quite understand why homebrew gcc cant be used to build boost. Obviously, boost can be built with gcc, but why not with homebrew gcc? What is so special about homebrew gcc?

If I build my own gcc then I can easily build boost (from source) using that gcc on macosx. However, if I use homebrew built gcc, I am unable to build boost using that gcc. I like to use homebrew to build all my libraries, so I’d prefer to build boost using homebrew, which is a great tool.

Clearly, there is no problem either with gcc or boost. Do folks who built homebrew have anything to say in this regard or have any idea how one could fix this issue?

https://github.com/Homebrew/homebrew-core/blob/master/Formula/boost.rb shows that homebrew builds boost using the macOS compiler by default so I can’t really say what to change to build it using a different configuration.

#include
#include <boost/regex.hpp>

int main(){
boost::regex begin_with_capital("[A-Z].*");
std::cout << boost::regex_match(“MacBook Pro”, begin_with_capital) << std::endl;
std::cout << boost::regex_match(“iPad Air”, begin_with_capital) << std::endl;
}

This code does not compile/link when using homebrew built gcc 9.3 and homebrew built boost.

Let me clarify my above statement. Homebrew can build gcc 9.3. Homebrew can also build boost, however it uses clang++. What I am looking for is a way to build boost using homebrew built gcc compiler so that I can compile/link the above piece of code using homebrew built gcc compiler.

The bottom line is: how can I build boost, boost-python3, boost-mpi using homebrew built gcc compiler so that I can compile the above code using gcc compiler?

I want to do everything with homebrew but absolutely don’t want to use clang.

I get what you’re trying to achieve but since homebrew doesn’t use this configuration I have no idea what is needed to support it.

Is there no way to build boost using homebrew built gcc, instead of a default clang compiler? I am not trying to use some arbitrary compiler. I am trying to use homebrew built gcc, so I am still within the domain of homebrew.

There might be, but homebrew doesn’t compile boost that way so I have no idea if there is.