Just put `clang 12.0.0` in macOS` Catalina` and put `ruby 3.0.0`

One day, I was watching rbenv

brew upgrade ebenv,

$ rbenv install -list

It seems that ruby 3.0.0 was officially released within last year, and rbenv is also supported. I wonder if I should put it in ...

I messed up trying to put that ruby 3.0.0

The environment at that time was as follows.

Error spit out

linking miniruby
generating x86_64-darwin19-fake.rb
x86_64-darwin19-fake.rb updated
make: *** [exe/ruby] Segmentation fault: 11
make: *** Deleting file 'exe/ruby'

BUILD FAILED (Mac OS X 10.15.7 using ruby-build 20201225)

Inspect or clean up the working tree at /var/folders/rk/0hczm32x2znb6pr6h4858hpc0000gn/T/ruby-build.20210104003100.75691.mUe6Zo
Results logged to /var/folders/rk/0hczm32x2znb6pr6h4858hpc0000gn/T/ruby-build.20210104003100.75691.log

Last 10 log lines:
compiling enc/unicode.c
compiling enc/utf_8.c
compiling enc/trans/newline.c
./revision.h unchanged
compiling version.c
linking miniruby
generating x86_64-darwin19-fake.rb
x86_64-darwin19-fake.rb updated
make: *** [exe/ruby] Segmentation fault: 11
make: *** Deleting file 'exe/ruby'

Apparently, I messed up at the last make.

Cause estimation

Segmentation fault: 11, I felt that the compiler was bad, so I wanted to see the settings and progress.

rbenv install -v 3.0.0

If you do rbenv install while -v, you can see various progress, the result

Configuration summary for ruby version 3.0.0

   * Installation prefix: /Users/username/.rbenv/versions/3.0.0
   * exec prefix:         ${prefix}
   * arch:                x86_64-darwin19
   * site arch:           ${arch}
   * RUBY_BASE_NAME:      ruby
   * enable shared:       yes
   * ruby lib prefix:     ${libdir}/${RUBY_BASE_NAME}
   * site libraries path: ${rubylibprefix}/${sitearch}
   * vendor path:         ${rubylibprefix}/vendor_ruby
   * target OS:           darwin19
   * compiler:            clang -fdeclspec
   * with pthread:        yes
   * with coroutine:      amd64
   * enable shared libs:  yes
   * dynamic library ext: bundle
   * CFLAGS:              ${optflags} ${debugflags} ${warnflags}
   * LDFLAGS:             -L. \
                          -L/Users/username/.rbenv/versions/3.0.0/lib  \
                          -fstack-protector-strong -L/usr/local/lib
   * DLDFLAGS:            -L/Users/username/.rbenv/versions/3.0.0/lib  \
                          -Wl,-undefined,dynamic_lookup \
   * optflags:            -O3
   * debugflags:          -ggdb3
   * warnflags:           -Wall -Wextra -Wdeprecated-declarations \
                          -Wdivision-by-zero \
                          -Wimplicit-function-declaration -Wimplicit-int \
                          -Wpointer-arith -Wshorten-64-to-32 \
                          -Wwrite-strings -Wmissing-noreturn \
                          -Wno-constant-logical-operand -Wno-long-long \
                          -Wno-missing-field-initializers \
                          -Wno-overlength-strings -Wno-parentheses-equality \
                          -Wno-self-assign -Wno-tautological-compare \
                          -Wno-unused-parameter -Wno-unused-value \
                          -Wunused-variable -Wextra-tokens
   * strip command:       strip -A -n
   * install doc:         rdoc
   * JIT support:         yes
   * man page type:       doc
   * BASERUBY -v:         ruby 2.7.2p137 (2020-10-01 revision 5445e04352) \

I failed in the same way while spitting.

   * target OS:           darwin19
   * compiler:            clang -fdeclspec

I can see that I am using the clang that comes with macOS (I haven't touched the compiler yet).

$ clang -v
Apple clang version 11.0.0 (clang-1100.0.33.8)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Apparently he used this for the build. When I was worried about wandering around Twitter, I found a ruby 3.0.0-like person in clang Apple 12.0.0. Also, according to ko ↑ ko ↓, those who have properly put XCode in macOS Big Sur

$ clang --version
Apple clang version 12.0.0 (clang-1200.0.32.27)
Target: x86_64-apple-darwin20.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

(I put in XCode and then ** erased it **, because it's big and heavy ...).

In other words, you messed up because the version of clang is old, right? I thought.



If you forcibly reinsert CommandLineTools, it will be clang 12.0.0, so Yoshi! You can also put ruby 3.0.0!


Even if you leave it to softoware update with Catalina, CommandLineTools will not be new anymore (that is, clang 12.0.0 will not be available no matter how you scratch it), so re-install it manually.

$ sudo rm -rf /Library/Developer/CommandLineTools
$ xcode-select --install

When checking the version

$ clang -v
Apple clang version 12.0.0 (clang-1200.0.32.28)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

It should be like this, after all it was okay without XCode ...

with this

$ rbenv install 3.0.0


Installed ruby-3.0.0 to /Users/username/.rbenv/versions/3.0.0

It's up to you to change the version or not

rbenv local 3.0.0

You can do it.

**the end! Closed! that's all! Everyone disbanded! ~~ You can go home ~~ **


I thought about what to do when I wanted to use clang 11.0.0 (or any earlier version of clang).


Let's put llvm in homebrew and change the version of clang arbitrarily via it?

What is llvm?

The official page of the organization that develops llvm is ko ↑ ko ↓, and the downloads and documents around llvm are ko ↑ ko ↓. llvm itself is a system that generates an intermediate language that seems to be running in the back of the c and c ++ compilers clang, or rather llvm corresponds to the c specification. It seems that it has been developed and maintained in parallel with ...? So from some time the version of llvm has been the version of clang, and the latest version available with brew is now llvm 11.0.0, with it clang 11.0 .0` will follow it without exception ...

However, it is llvm that tries to generate a more efficient intermediate language regardless of language and architecture, and it is clang that compiles objective-c etc. using it, and then After all, Apple is the starting point for the development of clang ... So, the latest version of clang 12.0.0 is included in XCode, and it's really an apple ...

... so clang has better performance and usability than gcc ... (I'm not a developer so I don't know at all).

Advance preparation

Introduce homebrew.

If you only need the latest version of llvm

First, let's put it in.

$ brew install llvm <versions>
$ brew info llvm

Read the notes properly (excerpt).

To use the bundled libc++ please add the following LDFLAGS:
  LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"

llvm is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have llvm first in your PATH run:
  echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> /Users/SolunaEureka/.bash_profile

For compilers to find llvm you may need to set:
  export LDFLAGS="-L/usr/local/opt/llvm/lib"
  export CPPFLAGS="-I/usr/local/opt/llvm/include"

keg-only ... In other words, it's a type of package that doesn't generate symbolic links, but the contents are correct, so let's just pass the path! It also supports flags that you want the compiler to know, so if you want to use it, just pass the path! (Free translation)

So, it seems that llvm as a command doesn't seem to work, so in order to make it feel like clang via llvm is valid, play with .bash_profile ([Reference] : Student's technical blog](https://students-tech.blog/post/install-clang.html#パスを通す)). ~~ I'm still sorry for bash ~~


function llvm (){ #Defining a function
    export PATH="/usr/local/opt/llvm/bin:$PATH" #Below, add / change the path as described in the previous note.
    export LDFLAGS="-L/usr/local/opt/llvm/lib"
    export CPPFLAGS="-I/usr/local/opt/llvm/include"
    unset -f llvm #Break this defined function once called

When you're done so far, restart terminal

$ llvm
$ clang -v
clang version 11.0.0
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin

Should be. Rest assured that opening a new tab will bring it back to normal!

If you want to use the old version of llvm

Homebrew is basically a man who never admits other than the latest version, and it seems that the specifications will change regarding the installation of the past version, but in such a situation, the current reference was ko ↑ ko ↓. It seems that you can use brew tap-new and brew extract to insert the official formula into your homemade tap, and then brew install from that tap. The person who came up with this is really smart ...

So I try to put llvm 10.0.0 and switch to clang 10.0.0 (extract the main output).

$ brew tap-new llvm/1000
Initialized empty Git repository in /usr/local/Homebrew/Library/Taps/llvm/homebrew-1000/.git/
[master (root-commit) d649d61] Create llvm/1000 tap
 3 files changed, 85 insertions(+)
 create mode 100644 .github/workflows/publish.yml
 create mode 100644 .github/workflows/tests.yml
 create mode 100644 README.md
==> Created llvm/1000

$ brew extract llvm llvm/1000 --version 10.0.0
==> Searching repository history
==> Writing formula for llvm from revision 96544f6 to:
/usr/local/Homebrew/Library/Taps/llvm/homebrew-1000/Formula/[email protected]

$ brew install llvm/1000/[email protected]
==> Installing [email protected] from llvm/1000
[email protected]: A full installation of Xcode.app is required to compile
this software. Installing just the Command Line Tools is not sufficient.

Xcode can be installed from the App Store.
Error: An unsatisfied requirement failed this build.

I was told that I couldn't do without XCode. What's this, I'm crazy ... If anyone has it, please give it a try.

I also want you to switch versions somehow ...


There are various compilers and it's difficult. Is there definitely a better way? brew is not suitable for version control, and llvm and clang should be DLed from the official website and thrust into it to build the function properly by yourself. I can't think of anything anymore because the problem has been solved ...

Recommended Posts

Just put `clang 12.0.0` in macOS` Catalina` and put `ruby 3.0.0`
Put CSV files containing "'" and "" "in MySQL in Ruby 2.3
How to put old Java (8 series) in macOS 10.15 Catalina
[Ruby] then keyword and case in
Write keys and values in Ruby
Make bubble sort and selection sort in Ruby
Summary of hashes and symbols in Ruby
Difference between "|| =" and "instance_variable_defined?" In Ruby memoization
[Understanding] Differences between hashes and arrays in Ruby
Put nginx 1.18 in CentOS6 and set reverse proxy
[Ruby] What if you put each statement in each statement? ??
Class in Ruby
Ruby and Gem
Differences between Ruby syntax error statements in Ruby and binary
About the difference between classes and instances in Ruby
In fact, Ruby distinguishes between line breaks and whitespace.
[Ruby] Difficulty in refactoring logical operators (accuracy and readability)
Install rbenv with apt on ubuntu and put ruby
How to handle TSV files and CSV files in Ruby
Handling of date and time in Ruby. Use Date and Time properly.
Beginners write! Until you install postgreSQL on macOS catalina and make it available in rails