kaleidoscope
kaleidoscope copied to clipboard
Run the first chapter on a mac
Hello,
I don't know if it's the good place to ask, so if I'm wrong don't be mad just tell me :) I'm running OSX. I installed llvm using brew and I compiled the first functions using llc. Now I have a test.s and I don't know how to run it.
I tried the command gcc test.s -o hello.native and I have now the error: test.s:2:2: error: unknown directive .macosx_version_min 14, 1
Does anyone knows why? Thanks
Same here:
➤➤ cc hello.s -o hello.native
hello.s:2:2: error: unknown directive
.macosx_version_min 14, 0
^
First 4 lines of hello.s
:
.section __TEXT,__text,regular,pure_instructions
.macosx_version_min 14, 0
.globl _add
.align 4, 0x90
And after I removed that line .macosx_version_min 14, 0
compilation just passed.
I have not used LLVM on a Mac before, so if there is any advice about how to change the wording so that it's Linux and Mac agnostic the Markdown is here and pretty quick to change: https://github.com/sdiehl/kaleidoscope/blob/master/tutorial.md#llvm-introduction
The problem is that GCC does not know about the macosx_version_min
directive. Clang does. So, if you have gcc installed as your default for gcc
or cc
, you have to call clang
explicitly.
A more serious problem is that on OS X, the current LLVM system default and the version provided by Homebrew are 3.6.0, which has no Haskell bindings yet.
If you're using brew, you can install LLVM 3.4 by brew install llvm34
. This will install all llvm commands with the -3.4
ending e.g. llvm-config-3.4
for llvm-config
. Aliasing llvm-config
to llvm-config-3.4
was enough of a hack for me to be able to build llvm-general
and llvm-general-pure
. But I have still not run the cabal project for myself so I don't know if I will face any other problems.
EDIT: The below is outdated. Simply follow the setup instructions in README.md
.
For future visitors: Old versions of Homebrew packages are now maintained here, so in order to install LLVM 3.5 and set up the Kaleidoscope tutorial, perform the following steps (tested on OS X El Cap):
brew tap homebrew/versions
brew install llvm35
brew install libffi # the version provided in OS X El Cap is too outdated
cabal sandbox init
cabal configure # or cabal configure --flags=tutorial, see README.md
alias llvm-config='llvm-config-3.5' # see comment by @ayberkt
cabal install llvm-general-3.5.1.2 --extra-lib-dirs /usr/local/opt/libffi/lib/ # more recent 3.5.*.* versions might work too
cabal install --only-dependencies