[LLVMdev] include's are not being located

Dan Liew dan at su-root.co.uk
Wed Jun 11 17:06:51 PDT 2014


On 12 June 2014 00:01, Joseph <its.jojo.77 at gmail.com> wrote:
> Hi Dan,
>
> Thank you for you response. As you suspect,  I am struggling with the
> building of LLVM/Clang.
>
> I thought building LLVM/Clang was required in order to build the tutorial
> and eventually modify for testing/learning. From what you are saying, it
> sounds like I am mistaken?

Well on many Linux distributions LLVM and Clang are installable as
packages (along with the header files) so for something like the
Kaleidoscope tutorial it isn't necessary to build LLVM and Clang from
source. However you are running OSX which I'm not familiar with so I
don't know what the situation is there. I know clang is now the
default compiler but I don't know if LLVM header files and libraries
are shipped with OSX or can be installed as the OSX equivalent of a
package.

So I can only really guide you on building LLVM and Clang from source.

Looking at the Kaleidoscope I didn't see anything that was actually
clang specific, for example this...

```
clang++ -g -O3 toy.cpp `llvm-config --cppflags --ldflags --libs core` -o toy
````

is building native code so you can use whatever C++ compiler you like
(you could even use gcc for example if you liked). So for the
Kaleidoscope tutorial I don't think it's necessary for you to build
clang (and consequently there's no reason to build compiler-rt
either).


> 4. #Change Directory to build but not sure why I’m doing this (Make is
> building everything in here)
> cd /Users/josephmorgan/build

You are doing what is called an "out of source build". This is where
all the generated binary files and some build system files go in a
different directory to the source code directory. This is the opposite
of an "in source build" where binary files and some build system files
go in the same directory as the source code directory. The advantage
of doing an "out of source build" is that

- you can have multiple build configurations all building from the
same source directory
- Prevents you from accidently committing files generated by the build system
- Deleting build files is really easy, you just delete the build
directory (  /Users/josephmorgan/build )

I would stick with doing out of source builds, so this is fine.

> 5. #configure (I am still not clear on what is purpose of prefix here)
> /Users/josephmorgan/llvm/configure --prefix=/Users/josephmorgan/build
> --enable-targets=x86,x86_64

If you read [1] you'll see that ``--prefix=`` is optional and that it
sets the install location. I think you are confused between "building"
and "installing". Building (i.e. running ``make``) builds the binaries
in the build directory (e.g. You'll probably find the built binaries
in /Users/josephmorgan/build/Release+Asserts/bin/). This does not
install the binaries. By running ``make install`` this will install

LLVM Binaries to <prefix>/bin
LLVM Libraries to <prefix>/lib
LLVM header files to <prefix>/include

where <prefix> is what was specified using ``--prefix=`` (or the
default /usr/local if it was not specified). Telling configure to
build and install LLVM in the same directory like you did does not
make any sense so if you're still confused just don't specify the
``--prefix=`` flag.

For the kaleidoscope tutorial it is actually not necessary to install
LLVM, you can use it directly from your build directory
(``/Users/josephmorgan/build``).

Once you've successfully built LLVM you can then build the
Kaleidoscope example by doing something like

```
clang++ -g -O3 toy.cpp
`/Users/josephmorgan/build/Release+Assert/bin/llvm-config --cppflags
--ldflags --libs core` -o toy
```

You should replace "Release+Asserts" with the build configuration you
used (just look in the build directory, the folder might be called
"Release" or "Debug" or "Debug+Asserts" instead).

To make life easier you could add the path to the built LLVM binaries
to your PATH

$ PATH=/Users/josephmorgan/build/Release+Assert/bin:$PATH

then you can just use llvm-config and the other tools directly without
specifying the full path to the tools each time.


[1] http://llvm.org/docs/GettingStarted.html#getting-started-quickly-a-summary

-- 
Dan Liew
PhD Student - Imperial College London




More information about the llvm-dev mailing list