Compiling haskell with llvm - macos

I'm starting to learn Haskell and I found out that ghc can compile using LLVM with the -fllvm flag. Whenever I use the flag, I get the error message:
<no location info>: error:
Warning: Couldn't figure out LLVM version!
Make sure you have installed LLVM 3.7
ghc: could not execute: opt
However, I have opt in my /usr/local/Cellar/llvm/3.9.0/ folder. I'm on a Mac OS X and I've installed the full LLVM with brew install llvm but error persists. Is this a genuine version problem where I have to unistall LLVM and reinstall its 3.7 version? Or is ghc having trouble finding opt and there is some kind of search path I can modify to fix the problem? Thanks for the help and have a great day.

The GHC documentation says that it's compatible with llvm-2.8+, but as you've discovered, it actually requires llvm-3.7.
The simplest way to get it is:
brew install llvm#3.7
This installs llvm binaries in your path with a -3.7 suffix, like clang-3.7. GHC will need the unadorned names, which are in a subdirectory:
export PATH=/usr/local/opt/llvm#3.7/lib/llvm-3.7/bin:$PATH

Related

macos llvm-symbolizer not found

I am trying to use address sanitization when calling my program with clang, however it doesn't seem to be installed. If I type which llvm-symbolizer I get llvm-symbolizer not found. I also checked under /usr/bin and /usr/local/bin and under the location where clang is installed /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin but still I can't find llvm-symbolizer (though there are other llvm-* executables in the last path).
Is there a way I can install this on macos? Also, I couldn't find it in brew. I am using clang built in macos: Apple clang version 12.0.0 (clang-1200.0.32.21).
My version of llvm-symbolizer was installed with Homebrew. You have to install llvm with brew install llvm to get it. It then shows up as:
% which llvm-symbolizer
/usr/local/Cellar/llvm/11.0.0/bin/llvm-symbolizer
By the way, some people may have installed llvm but not linked some binaries to path. The sure-fire way to add all llvm binaries to path is:
PATH="$PATH:$(brew --prefix)/opt/llvm/bin"
$(brew --prefix)/opt/llvm is a symbolic link to the most recent installed version of llvm, and bin is obviously the binaries therein.

Can't compile with gcc-4.9

I eventually want to use valgrind to find what is causing the occasional bizarre output in a C program which refines a model against experimental data using OpenMP parallel programming.
To avoid the use of the nominal gcc (ie clang) compiler, I used brew to install gcc-4.9 on my MacPro running Yosemite (OS x 10.10.5). However, when trying to compile my program with gcc-4.9, with or without -fopenmp, I get numerous error messages of the type:
/var/folders/qc/1j0gr_l48xnfd9001s6tt6f80000gn/T//ccRxnrnU.s:30597:suffix
or operands invalid for `movq'
I have no idea what the problem triggering these error messages is. Can anyone help?
The following summarises what was worked out in the comments section and did lead to the issue being resolved. Not all steps may be necessary, but most are probably good practice.
Step 1 - Clean up
If you have been trying lots of different, potentially incompatible, methods to get OpenMP set up, it is probably a good idea to clean them up first. So, something like:
brew rm --force gcc # or maybe gcc#4.9
Step 2 - Update Xcode and Command Line Tools
If you have upgraded macOS since installing Xcode, it is probably advisable to update Xcode and its "Command Line Tools"
Consider uninstalling and re-installing Xcode - it is available for free from the App Store.
Update/install the "Command Line Tools" after installing/updating with:
xcode-select --install
Step 3 - Install gcc
Now, try installing gcc afresh, ensuring that you use the --without-multilib option:
brew install gcc#4.9 --without-multilib
Hopefully you can now compile OpenMP code with:
/usr/local/bin/gcc -fopenmp program.c -o program
I am unsure exactly why the --without-multilib option is needed and prefer to quote #hristo-iliev:
Multilib usually refers to the coexistence of both 64-bit and 32-bit
versions of each library so that 32-bit software could be run on
64-bit OS. In the GCC case that probably refers to having all GCC
runtime libraries in "fat" Mach-O format, i.e. versions for both i386
and x86_64 in the same shared library file. It could be that libgomp
(the GNU OpenMP runtime library) cannot be built in such a way.
See this question.
Keywords: gcc, g++, GNU Compiler, OpenMP, fopenmp, -fopenmp, Xcode, multilib, Command Line Tools, macOS, OSX, homebrew, brew

using command-line clang, OS X 10.9.1, Xcode 5.0.2

I'd like to use the -fsanitize=address features of clang.
I'm on:
OS X 10.9.1 with Xcode 5.0.2
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
I'm running clang from the command line, and I'm getting the error:
clang: error: unsupported argument 'address' to option 'fsanitize='
I'm told this works, but searching around hasn't shown me the way; do I need to bring in a different version of clang?
Thanks!
The out-of-box version of clang on OS X does not implement support of Address Sanitizer. You will have to build your own version of clang from sources.
You need a different build of clang than the one apple gave you. The simplest way to get one (or more) is to install Homebrew http://brew.sh
and then
brew install llvm --with-asan
You could also try a prebuilt clang from http://llvm.org/releases/download.htm.
It's by no means impossible to build clang 'by hand', but last I checked it did take multiple checkouts to get the source tree. The other options should have you asaning in minutes.

Getting Warning while installing flink on MacBook "There is no C compiler on your system"

To get support I am installing fink on my MacBook Pro. After execute bootstrap script I am getting following error log
Checking package... looks good (fink-0.35.1).
Checking system... i386-apple-darwin12.4.0
This system is supported and tested.
Distribution: 10.8
Architecture: x86_64
Checking cc... not found.
ERROR: There is no C compiler on your system. Make sure that the Developer
Tools are installed.
I didn't find gcc in /usr/bin/ directory.
After reading here, I am guessing x-code provide default support for gcc compiler.
any one have idea what I should to get support of fink or if have any other way to get support of apt-get.
First, you need to install Xcode and its command line tools to get the gcc compiler
Make sure that you have working version of gcc in your /usr/bin directory
Create a symbolic link cc from installed gcc in /usr/bin

How can I update clang to 3.3 on Mac OS X 10.6

I'm running Mac OS X 10.6 and want to install TextMate 2, which is for Mac OS X 10.7+.
But all what it needs is a newer version of clang (LLVM), which is included in Lion and Mountain Lion. I read before here I can do that with MacPorts. So I used port install clang and MacPorts updated to clang-2.9, then clang-3.2 and finally clang-3.3. I thought, its updated now and I checked the version: clang --version. And it's not updated:
Apple clang version 2.0 (tags/Apple/clang-139) (based on LLVM 2.9svn)
Target: x86_64-apple-darwin10
Thread model: posix
So I copied the new clang file in this path (/opt/local/libexec/llvm-3.3/bin) to/usr/bin`. But now there's a fail :( :
dyld: Library not loaded: #executable_path/../lib/libLLVM-3.3svn.dylib
Referenced from: /usr/bin/clang
Reason: image not found Trace/BPT trap
The libLLVM-3.3svn.dylib is at /opt/local/libexec/llvm-3.3/lib. What can I do now, that
it runs clang-3.3? Sorry for my not perfect english ;) Thank you!
If you run clang from /usr/bin, it will be looking for the LLVM library in /usr/bin/../lib/libLLVM-3.3svn.dylib, i.e., /usr/lib/libLLVM-3.3svn.dylib (at least that's what the dynamic loader is telling you). You could try to copy the lib file into /usr/lib.
Alternatively, you can just download a more recent official build of Clang here:
http://llvm.org/releases/download.html
As far as I know, these builds are self-contained and do not need any dynamic libraries. However, it could be necessary to copy Apple's ARC libraries into a certain directory. If you run into trouble, please ask again.
Another approach is to build Clang and LLVM from source. You can find the repository URLs and instructions here:
http://clang.llvm.org/get_started.html
This should also build Clang with the LLVM libraries statically linked.
3.3, by the way, has not been officially released, so I would recommend using 3.2 unless you need any specific new features.

Resources