C++ Trying to build a Linux C++ program on FreeBSD 14 with gcc9

Hi, I'm trying to compile https://github.com/elixir-nx/xla on a FreeBSD 14 x86_64 system.

This project builds well on Linux and OSX, so it should build on FreeBSD.

The author explained their CI builds using GCC 9.x, so I installed gcc9-9.5.0_1 from pkg and tried to build, first using this command:

ROOT_DIR="$(pwd)" BUILD_ARCHIVE="~/xla_extension.tar.gz" make
also
CXXOPTS="-std=c++14" ROOT_DIR="$(pwd)" BUILD_ARCHIVE="~/xla_extension.tar.gz" make

Then both using gmake instead of make, but got similar results.

Code:
ERROR: /usr/home/informemedico/.cache/bazel/_bazel_informemedico/1fd8e3102f291348a56716ebce84006d/external/llvm-project/llvm/BUILD.bazel:219:11: Compiling llvm/lib/Support/APFixedPoint.cpp [for tool] failed: (Exit 1): clang failed: error executing command (from target @llvm-project//llvm:Support) /usr/bin/clang -U_FORTIFY_SOURCE '-D_FORTIFY_SOURCE=1' -fstack-protector -Wall -fno-omit-frame-pointer -g0 -O2 -DNDEBUG -ffunction-sections -fdata-sections '-std=c++0x' -MD -MF ... (remaining 65 arguments skipped)
In file included from external/llvm-project/llvm/lib/Support/APFixedPoint.cpp:14:
In file included from external/llvm-project/llvm/include/llvm/ADT/APFixedPoint.h:19:
In file included from external/llvm-project/llvm/include/llvm/ADT/APSInt.h:18:
In file included from external/llvm-project/llvm/include/llvm/ADT/APInt.h:19:
In file included from external/llvm-project/llvm/include/llvm/Support/MathExtras.h:16:
external/llvm-project/llvm/include/llvm/ADT/bit.h:84:21: error: no template named 'enable_if_t' in namespace 'std'
    typename = std::enable_if_t<sizeof(To) == sizeof(From)>,
               ~~~~~^
external/llvm-project/llvm/include/llvm/ADT/bit.h:85:21: error: no template named 'enable_if_t' in namespace 'std'
    typename = std::enable_if_t<std::is_trivially_constructible<To>::value>,
               ~~~~~^
external/llvm-project/llvm/include/llvm/ADT/bit.h:86:21: error: no template named 'enable_if_t' in namespace 'std'
    typename = std::enable_if_t<std::is_trivially_copyable<To>::value>,
               ~~~~~^
external/llvm-project/llvm/include/llvm/ADT/bit.h:87:21: error: no template named 'enable_if_t' in namespace 'std'
    typename = std::enable_if_t<std::is_trivially_copyable<From>::value>>
               ~~~~~^
external/llvm-project/llvm/include/llvm/ADT/bit.h:99:39: error: no template named 'enable_if_t' in namespace 'std'
template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
                                 ~~~~~^
external/llvm-project/llvm/include/llvm/ADT/bit.h:99:56: error: no template named 'is_integral_v' in namespace 'std'; did you mean 'is_integral'?

As you can see in the output, it looks like it uses /usr/local/bin/clang instead of gcc9.

Would anyone take a peek into this?
 
"and tell Bazel to use it with export CC=/path/to/gcc-{version} where version is the GCC version you installed."
 
Hi cracauer@, yes I've tried everything I could find, including:

export CC=/usr/local/bin/gcc9

then
CXXOPTS="-std=c++14" ROOT_DIR="$(pwd)" BUILD_ARCHIVE="~/xla_extension.tar.gz" make
or
CXXOPTS="-std=c++14" ROOT_DIR="$(pwd)" BUILD_ARCHIVE="~/xla_extension.tar.gz" gmake
or
ROOT_DIR="$(pwd)" BUILD_ARCHIVE="~/xla_extension.tar.gz" make

All similar results.
 
BUILD_ARCHIVE="~/xla_extension.tar.gz" might need to be replaced to BUILD_ARCHIVE="${HOME}/xla_extension.tar.gz"
With
gmake CC=/usr/local/bin/gcc9 CXXOPTS="--std=c++14" ROOT_DIR="$(pwd)" BUILD_ARCHIVE="${HOME}/xla_extension.tar.gz"

Code:
ERROR: /usr/home/informemedico/.cache/bazel/_bazel_informemedico/1fd8e3102f291348a56716ebce84006d/external/llvm-project/llvm/BUILD.bazel:360:11: Compiling llvm/lib/TableGen/StringMatcher.cpp [for tool] failed: (Exit 1): clang failed: error executing command (from target @llvm-project//llvm:TableGen) /usr/bin/clang -U_FORTIFY_SOURCE '-D_FORTIFY_SOURCE=1' -fstack-protector -Wall -fno-omit-frame-pointer -g0 -O2 -DNDEBUG -ffunction-sections -fdata-sections '-std=c++0x' -MD -MF ... (remaining 65 arguments skipped)
In file included from external/llvm-project/llvm/lib/TableGen/StringMatcher.cpp:13:
In file included from external/llvm-project/llvm/include/llvm/TableGen/StringMatcher.h:16:
In file included from external/llvm-project/llvm/include/llvm/ADT/StringRef.h:12:
external/llvm-project/llvm/include/llvm/ADT/DenseMapInfo.h:264:26: error: no template named 'tuple_element_t' in namespace 'std'; did you mean 'tuple_element'?
 
How about CXX=/usr/local/bin/g++9
With:
gmake CCX=/usr/local/bin/g++9 CC=/usr/local/bin/gcc9 CXXOPTS="--std=c++14" ROOT_DIR="$(pwd)" BUILD_ARCHIVE="${HOME}/xla_extension.tar.gz"

Code:
ERROR: /usr/home/informemedico/.cache/bazel/_bazel_informemedico/1fd8e3102f291348a56716ebce84006d/external/llvm-project/llvm/BUILD.bazel:219:11: Compiling llvm/lib/Support/xxhash.cpp [for tool] failed: (Exit 1): clang failed: error executing command (from target @llvm-project//llvm:Support) /usr/bin/clang -U_FORTIFY_SOURCE '-D_FORTIFY_SOURCE=1' -fstack-protector -Wall -fno-omit-frame-pointer -g0 -O2 -DNDEBUG -ffunction-sections -fdata-sections '-std=c++0x' -MD -MF ... (remaining 65 arguments skipped)
In file included from external/llvm-project/llvm/lib/Support/xxhash.cpp:41:
In file included from external/llvm-project/llvm/include/llvm/Support/xxhash.h:41:
In file included from external/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:12:
In file included from external/llvm-project/llvm/include/llvm/ADT/Hashing.h:49:
In file included from external/llvm-project/llvm/include/llvm/Support/SwapByteOrder.h:17:
external/llvm-project/llvm/include/llvm/ADT/STLForwardCompat.h:32:21: error: no template named 'remove_cv_t' in namespace 'std'; did you mean 'remove_cv'?
  using type = std::remove_cv_t<std::remove_reference_t<T>>;
 
Well, after reading a little more I found I can create a ~/.bazelrc file containing this:
Code:
build:gcc9 --cxxopt=-std=c++14
build:gcc9 --cxxopt=-Wall
build:gcc9 --cxxopt=-Werror
##build:gcc9 --cxxopt=-Wextra
build:gcc9 --define compiler=gcc9_5_0


Then append "--config=gcc9" to BAZEL_FLAGS in the Makfile.

Then run:
gmake ROOT_DIR="$(pwd)" BUILD_ARCHIVE="${HOME}/xla_extension.tar.gz"

As usual.

Now I see it is using gcc9, but still getting this error:
Code:
INFO: Found applicable config definition build:gcc9 in file /usr/home/informemedico/.bazelrc: --cxxopt=-std=c++14 --cxxopt=-Wall --cxxopt=-Werror --define compiler=gcc9_5_0
INFO: Analyzed target //xla/extension:xla_extension (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /usr/home/informemedico/.cache/bazel/_bazel_informemedico/1fd8e3102f291348a56716ebce84006d/external/llvm-project/llvm/BUILD.bazel:219:11: Compiling llvm/lib/Support/APSInt.cpp [for tool] failed: (Exit 1): clang failed: error executing command (from target @llvm-project//llvm:Support) /usr/bin/clang -U_FORTIFY_SOURCE '-D_FORTIFY_SOURCE=1' -fstack-protector -Wall -fno-omit-frame-pointer -g0 -O2 -DNDEBUG -ffunction-sections -fdata-sections '-std=c++0x' -MD -MF ... (remaining 65 arguments skipped)
In file included from external/llvm-project/llvm/lib/Support/APSInt.cpp:14:
In file included from external/llvm-project/llvm/include/llvm/ADT/APSInt.h:18:
In file included from external/llvm-project/llvm/include/llvm/ADT/APInt.h:19:
In file included from external/llvm-project/llvm/include/llvm/Support/MathExtras.h:16:
external/llvm-project/llvm/include/llvm/ADT/bit.h:84:21: error: no template named 'enable_if_t' in namespace 'std'
    typename = std::enable_if_t<sizeof(To) == sizeof(From)>,
 
You can see on this line that it's still deciding to use clang...

ERROR: /usr/home/informemedico/.cache/bazel/_bazel_informemedico/1fd8e3102f291348a56716ebce84006d/external/llvm-project/llvm/BUILD.bazel:219:11: Compiling llvm/lib/Support/APSInt.cpp [for tool] failed: (Exit 1): clang failed: error executing command (from target @llvm-project//llvm:Support) /usr/bin/clang -U_FORTIFY_SOURCE '-D_FORTIFY_SOURCE=1' -fstack-protector -Wall -fno-omit-frame-pointer -g0 -O2 -DNDEBUG -ffunction-sections -fdata-sections '-std=c++0x' -MD -MF ... (remaining 65 arguments skipped)

You're going to need someone who knows where the bodies are buried in their build system to figure out what is going on, or find where it is grabbing '-std=c++0x' and change it to '-std=c++14'.
 
Back
Top