gcc appears to be misconfigured in macOS Big Sur - clang

I've been trying to build GCC 10.2 on my Intel MBP. As I've always done, I'm building from source and installing on /usr/local. Trouble is no matter what, the build fails on STAGE2 of bootstrapping. A careful search on all logs (including dependencies) could not point to a single fault. The only thing that stood out was the clang setup from Xcode Command Line Tools. When I run 'gcc -v' on a clean system (empty /usr/local), it outputs:
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin20.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Trouble is that the target for --with-gxx-include-dir doesn't exist! There is no c++ subfolder, to begin with. Although there is one from the --prefix tree, instead of 4.2.1, there is just a v1 subfolder.
It would appear that there is something terribly wrong with Xcode Command Line Tools. But I can't be sure that this is the cause of my own troubles.
Please, don't answer this post pointing me to a package manager... there's a reason I abandoned those years ago. Also, it would be off-topic to the issue at hand.

I've finally managed to isolate the issue. GCC 10.2 depends on GMP, MPFR, MPC, and ISL libraries. I had them manually installed with the latest version available and fine tuned to my system. I didn't explore if it was a version conflict, or a fine tuning issue, but that broke the build. The solution was to let the script 'contrib/download_prerequisites' (within gcc tree) download the appropriate versions that were built along with GCC.
I also found out that the '--with-gxx-include-dir' target is a non-issue. It isn't supposed to point anywhere in my system. It is a reference to the system that built the "gcc" provided by Xcode Command Line Tools.

Related

runtime clang/clang++ with non-standard gcc install?

Is there a way to get clang/clang++ to use a gcc/g++ installation in a non-standard (i.e. not /usr) place?
I'm trying to get AMD's AOCC 4.0 compiler to work. They provide a pre-compiled version that you just unpack. The problem is that it seems to assume gcc is in /usr/lib/gcc/... In my case I'm on CentOS 7 so that's gcc 4.8.5. I want to use newer gcc's install in /sw/opt (and managed with environment modules) but even if the gcc is in my path, clang only finds that 4.8.5 version in /usr. This is also a problem in that I have a cluster that has no default gcc installed (but many gcc versions installed in /cluster/sw) and I can't get clang to see them.
When I want LLVM I usually just build from scratch and specify GCC_INSTALL_PREFIX but that only seems to be useful at build time and since AMD only provides executables I'm out of luck.
Ideally I'd like to get clang/clang++ to point to another gcc (en mass: include, libs, etc...) or not be dependent on gcc at all.
AOCC seems to be based on 14.0.6 if that matters:
AMD clang version 14.0.6 (CLANG: AOCC_4.0.0-Build#434 2022_10_28) (based on LLVM Mirror.Version.14.0.6)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /sw/opt/aocc-compiler-4.0.0/bin
After more poking around I've discovered that there is a clang option "--gcc-toolchain" that seems to address this. Some clang documentation also lists an option "--gcc-install-dir" but neither the 14.0.6 based version of AOCC nor the 16.0.0 based version of OneAPI (2023.0) seem to recognize it. I don't see it in the output of "clang --help" either so who knows.

Is it required to build LLVM in order to build hipSYCL?

I'm running Centos 7 and am trying to build hipSYCL (see here)
The issue is that hipSYCL needs to have cmake info from the LLVM build (via the LLVM_DIR cmake variable).
This is problematic for me because building LLVM requires a massive 35Gb for the libraries and exes. I don't have that much memory to spare.
I did find a build of llvm-toolset-8.0 online for Centos 7 and installed it, but to my surprise, that didn't seem to work with LLVM_DIR because there's no cmake files (since I didn't build it locally).
So, my question would be, is there a way to build hipSYCL using pre-built LLVM-clang?
If I'm missing or misunderstanding something, I'd appreciate any help.
LLVM publishes the necessary cmake files, and the binary OS packages I've seen include it, generally in a directory called /usr/lib/llvm*/lib/cmake and in a package called something like llvm-*-dev.

Do i need to install Command Line Tools for Xcode separately if i already have Xcode

I tried to install gcc 5.2 (already installed dependencies successfully) from source file on my computer one week ago, but it failed at make phase or make install phase because of missing some ****.h files, whatever, i can not remember clearly.
I searched the reason online, and looks like it is because i did not installed Command Line Tools for Xcode. But I already have Xcode 7.1.1 and i think it includes the Command Line Tool. I find it from File -> New -> project -> OS X Application -> Command Line Tool. I can also use gcc --version in the terminal.
So do i need to install Command Line Tools separately? If I need, and why?
did you try to download it like described in the attached images:
If you have installed Xcode you have installed command line tools too. Xcode installs command line tools automatically the first time you open it ("Installing additional components" is the message you see on the screen).
Actually xcode cannot function without the command line tools (build, git etc).
short answer: no, you don't.
this is the official description for the Command Line Tools for Xcode (from the https://developer.apple.com/download/all/):
This package enables UNIX-style development via Terminal by installing command line developer tools, as well as macOS SDK frameworks and headers. Many useful tools are included, such as the Apple LLVM compiler, linker, and Make. If you use Xcode, these tools are also embedded within the Xcode IDE.
long answer: it depends.
for example, if you're using homebrew package manager it requires CLT
(from homebrew member comment https://github.com/Homebrew/brew/issues/10714#issuecomment-786663987)
The reason we need the Command Line Tools rather than just Xcode.app is for a few reasons:
The CLT contains more SDKs than Xcode - Xcode usually only contains one SDK, and it may be newer than your OS, while the CLT always has a compatible SDK. Having a matching SDK is very important for some formulae.
The CLT is in a fixed location /Library/Developer/CommandLineTools while Xcode is not. This matters as some formulae (including Python) bake in paths into files at compile-time - if they pointed to Xcode then it will only work for people who have Xcode installed in the same place.

Compiling C Source for iOS

I have some existing source code that is written in C that I want to build and include in my iOS project. The entire source package is very large and is built using existing Makefiles and GCC. It is producing static libraries (.a files) that I would love to move over to my iOS project. However, the static libraries the Makefile produces is for x86 processors, which obviously won't work on iOS.
Is there a way I can switch GCC to build for ARMv7/ARM64 instead, without making changes to the existing source (in most cases)? I know there is the -march switch for GCC or you can download ARM specific GCC compilers, so I know the general concept of building for a different architecture than the build machine.
To build for ARM on Mac OS, will I have to download a different GCC compiler or is that capability built into the default GCC?
I'm sorry for the lack of understanding of basic concepts here; I'm primarily a Java and Objective-C developer, so building source for different architectures is a mostly foreign concept to me.
Whilst GCC supports a good many CPU architecture and platforms, it is usually built for a single one. To compile for ARM you generally need an ARM-cross-compiling GCC targeted appropriately.
The default system compiler for MacOSX and iOS for all architectures is clang and has been for some time (the last version of GCC apple shipped in dev tools is creaking and obsolete, and definitely won't support ARMv8).
The usual way of getting clang is to install Xcode (free from the App Store). There's a option in the installer (and in the UI of Xcode) to install the command-line tool package. This installs sym-links in /usr/bin to the compiler, and installs a bunch of other stuff you might expect such as make.
clang is (mostly) command-line compatible with gcc, and furthermore, you'll find that if you run gcc from the command-line on a Mac with dev-tools installed, you in fact get clang.
$ gcc --version
Configured with: -- prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix
clang comes with ARMv7, ARMv8, i686, x86_64 on MacOSX, and can be configured to compile for any of these from the command line (See documentation)
Given the above, there's a fair chance your code will compile with minimal changes to compiler-flags using the existing makefile. You might want to read the documentation for lipo - which allows you to produce multi-architecture binaries.

Building Clang, libstdc++4.6 to libstdc++4.7

I am trying to build Clang following this: http://clang.llvm.org/get_started.html
At step 6 the command ../llvm/configure runs a series of checks and one tells me:
checking whether Clang will select a modern C++ standard library... no
configure: error:
We detected a missing feature in the standard C++ library that was known to be
missing in libstdc++4.6 and implemented in libstdc++4.7. There are numerous
C++11 problems with 4.6's library, and we don't support GCCs or libstdc++ older
than 4.7. You will need to update your system and ensure Clang uses the newer
standard library.
If this error is incorrect or you need to force things to work, you may pass
'--disable-compiler-version-checks' to configure to bypass this test.
I don't know how to resolve this and google searches for libstdc++4.7 did not produce anything useful to me or something I understand. How do I go about replacing / upgrading this? I am on a Mac (10.7.5)
I ran into the same problem. The easiest way to build Clang is to use libc++ instead of libstdc++. If you don't have libc++, you can obtain it by installing XCode 4.2 (or newer) or you can build it yourself by following the instructions here: http://libcxx.llvm.org/
After you have libc++ installed, you can use the --enable-libcpp=yes flag with the configure command.
Just this week, the LLVM & Clang project upped the minimal compiler version requirement to gcc 4.7, with its libstdc++. You'll need to install or build a newer gcc.
Here's a blog post I wrote earlier today about building gcc 4.8 on Ubuntu 12.04 and using that to compile trunk LLVM & Clang. Hope this helps!
i have the same error on mac 10.8.5 xcode 5.0
configure option --enable-libcpp resolve my problem
../llvm/configure --enable-cxx11 --enable-optimized --enable-libcpp
For me this happened because I had the old clang and clang++ that I'd previously built from source (the one I was attempting to build to replace) coming first in my PATH. These were too old. Removing those two files so that the build process would use the clang and clang++ that comes with XCode's Command Line Tools and then rebuilding worked fine.

Resources