Installing LLVM libraries along with Xcode - macos

So I just installed Xcode on my Mac and now I would like to install LLVM as well in order to play around a bit with LLVM itself. Currently the compiler can (obviously) not find the required header files. So what is the best way to install LLVM if you already have clang, packed with Xcode, on your system?
Thanks in advance.

If you do not need to read LLVM implementation source code(such as in lib/tools directories) and might only play with libclang, perhaps using homebrew is enough for you.
brew install --with-clang --with-lld --with-python --HEAD llvm
Next you need to set PATH, CPLUS_INCLUDE_PATH and LD_LIBRARY_PATH. For me,
# export PATH=/usr/local/opt/llvm/bin:$PATH
# export CPLUS_INCLUDE_PATH=$(llvm-config --includedir):$CPLUS_INCLUDE_PATH
# export LD_LIBRARY_PATH=$(llvm-config --libdir):$LD_LIBRARY_PATH
You might configure the above information in your LLVM derived project with XCode.
However if you are also interested in Compiler-RT, Clang-Tools-Extra(see LLVM Download Page) you probably have to make LLVM as your XCode project (download from that page or via SVN as said in Getting Started with the LLVM System). After putting the sub-projects in proper directories, you can use XCode generator from CMake, the typical usage is:
cd YOUR_LLVM_SRC_ROOT
mkdir build
cd build
cmake -G Xcode ..
Use XCode to open the project file XXX.xcodeproj and it should build the project.

I tried brew install --with-clang --with-lld --with-python --HEAD llvm as suggested in the other answer, but it gave me an error:
Error: invalid option: --with-clang
brew options llvm also showed nothing.
Then I found another page that suggests the simple
brew install llvm
This worked for me. It is with homebrew 2.4.0, on MacOS Mojave.
If you need to have llvm first in your PATH run (replace <your_username> with your username):
echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> /Users/<your_username>/.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"

Related

Replacing old Xcode command line tool with newer Brew version

I'm trying to build a binary from source code which has a dependency on the package" NASM 2.12.02 or later. However, I have an earlier version already installed on my Mac via Xcode:
/usr/local/bin/nasm -v
NASM version 0.98.40 (Apple Computer, Inc. build 11) compiled on May 1 2018
So to (attempt to) rectify this, I used Homebrew to install a much newer version of the package
brew info nasm
nasm: stable 2.13.03 (bottled), HEAD
However, now my PATH is only pointed to the old NASM executable, while the new tool seems to be sitting in Homebrew's Cellar (ie. /usr/local/Cellar/nasm/2.13.03).
Is there a nice way of "switching" between these versions so that the system PATH views only the newer version and disregards the older one? So far I've thought of rm -rf-ing the old version and exporting the new version to my PATH, but that seems very destructive.
Also, I have run the command: brew doctor and have resolved all linker errors, but that has not seemed to help.
Any help would be greatly appreciated!
To fix this, I used the following command:
export PATH=/usr/local/Cellar/nasm/2.13.03/bin:$PATH
This modifies the PATH variable to point to the /usr/local/Cellar/nasm/2.13.03/bin directory and find the nasm executable there before looking in /usr/local/bin.

How to disable Apple's LLVM on mac

I started to learn about Mix IDE and the thing is that, while compiling the Mix IDE, it keeps failing to compile source in the package. So I've done some search and it turns out that I need to use old version llvm. So I installed llvm37 using home-brew and there was no problem while installing it. The only problem is that when I type
clang --version
it keeps returning the following result.
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Therefore, I need to know how to disable the default LLVM and use the one I installed with Homebrew. Any idea?
You have several options:
Modifying PATH
Put Homebrew's binary path before everything else:
export PATH=/usr/local/bin:$PATH
Uninstalling Xcode command line tools
This will remove the command line tools that are delivered along Xcode.
sudo /Developer/Library/uninstall-devtools --mode=all
If you installed the command line tools without Xcode, see this question. Please be aware that Homebrew might depend on some of those tools and may cease to function! I did not test it.
Setting the desired compiler
This is the cleanest solution. Tell the Mix IDE's build system which compiler to use. Since I do not know which build system Mix IDE uses, I cannot tell you how to do that. Some build systems honor the CC, CXX and CPP environment variables, so it may work setting those to the clang binary installed with Homebrew.

Clang version 1.6 cannot be updated

I have a very strange issue with clang. I'm running OSX 10.10.1 and have installed XCode 6.1.1 from here. For another project, I wanted to update Ruby from 2.1.2 to 2.2.0 via rbenv install 2.2.0. The command prints the following error:
Downloading ruby-2.2.0.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/7671e394abfb5d262fbcd3b27a71bf78737c7e9347fa21c39e58b0bb9c4840fc
Installing ruby-2.2.0...
BUILD FAILED (OS X 10.10.1 using ruby-build 20141225)
Inspect or clean up the working tree at /var/folders/4z/s4lwbd314_lg3hprgp72qsqr0000gn/T/ruby-build.20150112115924.6502
Results logged to /var/folders/4z/s4lwbd314_lg3hprgp72qsqr0000gn/T/ruby-build.20150112115924.6502.log
Last 10 log lines:
Via: 1.1 2ce6276171358bf7d052aa190ed98f8d.cloudfront.net (CloudFront)
X-Amz-Cf-Id: 42q6Sa73ORpGbCgaHIpsBwTRP8ycUAhsdTolikEbyxqMrn9uePtfCA==
/var/folders/4z/s4lwbd314_lg3hprgp72qsqr0000gn/T/ruby-build.20150112115924.6502/ruby-2.2.0 /var/folders/4z/s4lwbd314_lg3hprgp72qsqr0000gn/T/ruby-build.20150112115924.6502 /usr/bin
checking build system type... x86_64-apple-darwin14.0.0
checking host system type... x86_64-apple-darwin14.0.0
checking target system type... x86_64-apple-darwin14.0.0
clang: error: invalid version number in '-mmacosx-version-min=10.10.0'
configure: error: clang version 3.0 or later is required
make: *** No targets specified and no makefile found. Stop.
Googled for invalid version number in '-mmacosx-version-min=10.10.0' but I did not find any helpful information. By running clang --version it turns out that my clang executable is version 1.6 (!):
Apple clang version 1.6 (tags/Apple/clang-70)
Target: x86_64-apple-darwin14
Thread model: posix
This seems very weird, because XCode is usually shipped with LLVM 6. I tried to (re)install the Command Line Tools (in which clang should be located), but XCode doesn't offer me the option to download/update them:
Trying to install them via xcode-select via the command line: xcode-select --install as suggested here results in showing the help message, indicating that the --install-command is unknown (xcode-select is version 895). I also tried to download and install it manually but it has absolutely no effect. The xcode-select-path is /Applications/Xcode.app/Contents/Developer but I also tried /Applications/Xcode.app.
I also tried to update clang via Homebrew:
$ brew install llvm --with-clang --with-asan
[...]
LLVM executables are installed in /usr/local/opt/llvm/bin.
Extra tools are installed in /usr/local/opt/llvm/share/llvm.
$ brew install llvm --with-clang --with-asan
Warning: llvm-3.5.0_2 already installed
but in none of the two paths is a clang executable.
So my question is: Is there a way to update clang? Or a workaround to install ruby 2.2.0 anyway? I'm stuck here for days, any help is greatly appreciated!
EDIT
I found out that newer XCode versions (I think from 5.0 upwards) come with LLVM/Clang inside the XCode.app-folder. A few months ago, I installed XCode 4.something for testing purposes - these versions overwrite system tools like clang and xcode-select. Reinstalling XCode 6 will not update them.
I fixed it by copying /usr/bin from another Mac, but there must be a way to fix it without this workaround.

Downgrade or remove GCC 4.8 from Mac OS X Mountain Lion

I am in the process of trying to essentially start from scratch with getting homebrew, GCC and RVM 1.9.3 on to my mac OS x 10.8.2 after determining that my problems with RVM were "related to a messy environment which can not be fixed automatically without what we plan for RVM2" in a thread that began here on SO and ended as a github for ticket RVM.
I had XCode 4.6 with Command Line Tools installed as was recommended here but at this point have completely deleted XCode (by trashing it- due to the version sudo /Developer/Library/uninstall-devtools --mode=all did not work), I uninstalled homebrew by running
cd `brew --prefix`
brew install libtool
rm -rf Cellar
rm `git ls-files`
rm -r Library/Homebrew Library/Aliases Library/Formula Library/Contributions
rm -rf .git
rm -rf ~/Library/Caches/Homebrew
and imploded my rvm. However, I am not sure how to go about 'refreshing' my GCC situation. Which is as follows:
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
Target: x86_64-apple-darwin12.2.0
Configured with: ../gcc-4.8-20130113/configure --enable-languages=c++,fortran
Thread model: posix
gcc version 4.8.0 20130113 (experimental) (GCC)
I have Time Machine backups from various stages of my undoing and made a bootable USB of Mountain Lion but was hoping to try reinstalling a fresh copy of Xcode or running the GCC-10.7 program installer before using either of those methods. However, I don't know if I can or how I would rectify the GCC situation before doing so.
From reading Change to GCC 4.7.., it seems that there might be a way of pointing/directing my system to a different version of GCC, but I don't know how to do that without MacPorts or homebrew.
Is there a way to get rid of the experimental GCC 4.8 so it doesn't come back in the future?
I have run a VM of my system with a copy of /usr/local/ from before I had ever installed XCode CLT or any of these other libraries, but my $ gcc -v still came back with gcc version 4.8.0
Sorry if I omitted and/or added necessary/unnecessary information and thank you in advance for any help.
This is a confusing dump of information. You don't want to use MacPorts or Homebrew? I seriously recommend you go with Homebrew. That should get the latest GCC 4.8 onto OR OFF OF your box with ease. If you can't figure out where your current gcc 4.8 is, try typing "which gcc" and that will tell you where it's located. It's not coming back. Clearly you never removed it if typing gcc brings up gcc. It's probably in /usr/local/opt.
If you insist on wiping out ALL the homebrew stuff manually, you COULD just zap /usr/local/opt to get rid of the symlinks, and /usr/local/Cellar to get rid of the real stuff, but I don't recommend it. Why? Zapping directories by hand could cause you to lose data especially if you're prone to making mistakes. Use MacPorts or Homebrew to REMOVE whatever you used it to install.

Gcc 4.2 version missing

on my new macbook pro with osx lion and XCode 4.1 I have some problems with gcc.
In /usr/bin I cannot find gcc-4.2
I only have the following versions:
i686-apple-darwin11-llvm-gcc-4.2
llvm-gcc
llvm-gcc-4.2
As a result when I try to select gcc42 by means of port select --set gcc gcc42 it returns me the following error:
Selecting 'gcc42' for 'gcc' failed: could not create new link "/opt/local/bin/gcc": target "/usr/bin/gcc-4.2" doesn't exist
However port select gcc returns me the following versions:
apple-gcc42
gcc42
llvm-gcc42 (active)
mp-gcc44
How can I fix this problem?
Thanks!
I could manage to solve this issue in Mountain Lion with a symbolic link:
sudo ln -s /usr/bin/llvm-gcc-4.2 /usr/bin/gcc-4.2
Hope this help someone
There should be a /usr/bin/gcc-4.2 with Xcode 4.1 installed. However, with the recent Xcode 4.2 update, Apple has finally removed their modified standard gcc-4.2. What remains is either llvm-gcc42 (also symlinked to gcc) and clang, the newer non-gcc C compiler. Apple is making the transition to clang; the first step is using the hybrid llvm-gcc42. There have been some reported problems using either of the new compilers. You should be using this time to figure out if you have problems with them and, if so, fix your code and report bugs to Apple. In the meantime, if you absolutely have to have the old gcc-4.2, it is possible to build one similar to the previous Apple-modified one via MacPorts:
port install apple-gcc42
but you'll be swimming against the tide.
With Xcode 4.3, you need to install the Command Line Tools separately. XCode -> Preferences -> Downloads, Click the Components button, and then click Install next to the "Command Line Tools" option.
I had the same issue.
I fixed it by doing a symlink.
Like this :
cd /usr/bin
then :
sudo ln -s llvm-gcc-4.2 gcc-4.2
You might consider compiling a newer GCC (e.g. 4.6.2) from its source code. Apple does not care much any more about GCC, but GCC has made significant progress since 4.2
And you probably could use your llvm-gcc42 as a GCC compiler.
I tampered with the innards of the makefile and found out that one invoked option provided an argument too many; replaced the variable with the actual result of the function called on my machine (removing the excess argument) and did run make again it worked.

Resources