include's are not being located

I’m new to llvm so I’m hoping someone can shed some light on this. I am trying to use the Kaleidoscope tutorial and cannot get past the 3rd part. All the llvm includes are not in their expected places. Eg… “llvm/IR/Verifier.h” is actually in “llvm/include/llvm/IR”. I am running mac osx 10.9.

Here’s what I’ve tried:

  1. checkout the svn of llvm, clang & compiler rt
  2. created a “build” directory & cd build
  3. …/llvm/configure --prefix=/HomeDir/build --enable-targets=x86,x86_64
  4. make -I/HomeDir/llvm/include <—- I thought this would fix my problem but it hasn’t

I am hoping I am not the only person who has experienced this and someone can help me get past it.

Thank you in advance.

Joseph

Hi Joseph,

It's not entirely clear from your e-mail which part you are struggling
with. You say you're having problems building the Kaleidoscope
tutorial but your steps look like you're struggling building
LLVM/Clang.

I’m new to llvm so I’m hoping someone can shed some light on this. I am
trying to use the Kaleidoscope tutorial and cannot get past the 3rd part.
All the llvm includes are not in their expected places. Eg…
“llvm/IR/Verifier.h” is actually in “llvm/include/llvm/IR”. I am running mac
osx 10.9.

Are you trying to build this [1]? I.e. When you do

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

If so you should make sure that the llvm-config command being executed
here is the one you built (assuming that's what you want) rather than
you system's one. Take a look at what llvm-config actually outputs.
E.g. on my system I get

$ llvm-config --cppflags --ldflags --libs core
-I/home/dan/dev/llvm/src/include -I/home/dan/dev/llvm/bin/include
-D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS
-D__STDC_LIMIT_MACROS
-L/home/dan/dev/llvm/bin/lib
-lLLVMCore -lLLVMSupport

What you've described below sounds like you're struggling to build
LLVM/Clang which is not what you said you were trying to do earlier
(build the Kaleidoscope tutorial). Please clarify.

Assuming this is an attempt to build LLVM/Clang I can see a few mistakes here.

Here’s what I’ve tried:
1. checkout the svn of llvm, clang & compiler rt
2. created a “build” directory & cd build
3. …/llvm/configure --prefix=/HomeDir/build --enable-targets=x86,x86_64

I assume you mean ``..`` not ``...``

--prefix= is used to instruct the build system where to install
LLVM/Clang. I might be misreading this because you have not said where
you created the ``build`` directory but it looks like you've set
--prefix to where you are building LLVM. I highly recommend you do not
do that (it will make a mess if you ever run ``make install``). In
your case if you are trying to build the Kaleidoscope tutorial you
shouldn't even need to install LLVM/Clang.

4. make -I/HomeDir/llvm/include <—- I thought this would fix my problem but

I can see what you're trying to do but that's not how you pass flags
to the C++ compiler for LLVM's build system (or for any other make
file based build system for that matter).

It would be

$ make CXXFLAGS=" -I/HomeDir/llvm/include"

Even this not quite right because it will overwrite CXXFLAGS and does
not append so it is likely this will break the build in some way. So I
don't recommend doing this.

[1] http://llvm.org/docs/tutorial/LangImpl3.html#full-code-listing

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?

In reference to what you mentioned about installing/building and —prefix and my misuse of my build directory:

I am following instruction from the getting started page:
http://llvm.org/docs/GettingStarted.html#getting-started-quickly-a-summary

Here are exactly the steps I follow to download/build LLVM/Clang:

  1. #llvm
    cd /Users/josephmorgan
    svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm

  2. #clang
    cd llvm/tools
    svn co http://llvm.org/svn/llvm-project/cfe/trunk clang

  3. #compiler rt
    cd llvm/projects
    svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt

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

  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

  6. #make/build
    make

Attempts to build the following:
clang++ -g -O3 toy.cpp llvm-config --cppflags --ldflags --libs core -o toy

Yields the following errors:

llvm-config: command not found

toy.cpp:1:10: fatal error: ‘llvm/Analysis/Verifier.h’ file not found

Thank you for any advice you can offer.

Joseph

Hi Joseph,

It’s not entirely clear from your e-mail which part you are struggling
with. You say you’re having problems building the Kaleidoscope
tutorial but your steps look like you’re struggling building
LLVM/Clang.

I’m new to llvm so I’m hoping someone can shed some light on this. I am
trying to use the Kaleidoscope tutorial and cannot get past the 3rd part.
All the llvm includes are not in their expected places. Eg…
“llvm/IR/Verifier.h” is actually in “llvm/include/llvm/IR”. I am running mac
osx 10.9.

Are you trying to build this [1]? I.e. When you do

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

If so you should make sure that the llvm-config command being executed
here is the one you built (assuming that’s what you want) rather than
you system’s one. Take a look at what llvm-config actually outputs.
E.g. on my system I get

$ llvm-config --cppflags --ldflags --libs core
-I/home/dan/dev/llvm/src/include -I/home/dan/dev/llvm/bin/include
-D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS
-D__STDC_LIMIT_MACROS
-L/home/dan/dev/llvm/bin/lib
-lLLVMCore -lLLVMSupport

What you’ve described below sounds like you’re struggling to build
LLVM/Clang which is not what you said you were trying to do earlier
(build the Kaleidoscope tutorial). Please clarify.

Assuming this is an attempt to build LLVM/Clang I can see a few mistakes here.

Here’s what I’ve tried:

  1. checkout the svn of llvm, clang & compiler rt
  2. created a “build” directory & cd build
  3. …/llvm/configure --prefix=/HomeDir/build --enable-targets=x86,x86_64

I assume you mean .. not ...

–prefix= is used to instruct the build system where to install
LLVM/Clang. I might be misreading this because you have not said where
you created the build directory but it looks like you’ve set
–prefix to where you are building LLVM. I highly recommend you do not
do that (it will make a mess if you ever run make install). In
your case if you are trying to build the Kaleidoscope tutorial you
shouldn’t even need to install LLVM/Clang.

  1. make -I/HomeDir/llvm/include <—- I thought this would fix my problem but

I can see what you’re trying to do but that’s not how you pass flags
to the C++ compiler for LLVM’s build system (or for any other make
file based build system for that matter).

It would be

$ make CXXFLAGS=" -I/HomeDir/llvm/include"

Even this not quite right because it will overwrite CXXFLAGS and does
not append so it is likely this will break the build in some way. So I
don’t recommend doing this.

It sounds like I was going in the wrong direction with CXXFLAGS in this case and it’s not needed.

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

Hi Dan,

Thank you for your advice on the build/install.

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.

It doesn’t appear to be installed on mac osx by default (it’s not on either of my two machines).

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.

This makes sense to me now. :slight_smile:

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.

I am now leaving out the ``--prefix=`` flag when I make install it was able to find the includes as expected.

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

I also tried this before doing a make install and it was able to find the includes as expected. Not having it originally installed in usr/local was really what caused my confusion. Installing in the build folder as you suggested in an earlier email was the culprit for me. Had I not specified "—prefix=“ flag all the includes would have been located automatically. I didn’t know that I needed to specify where the binary was for llvm-config. So I understand now.

So now that the includes are being found building the tutorial results in 74 warnings and 20 errors. Heres a couple examples:

In file included from /usr/local/include/llvm/IR/DerivedTypes.h:21:
In file included from /usr/local/include/llvm/IR/Type.h:19:
In file included from /usr/local/include/llvm/ADT/APFloat.h:20:
In file included from /usr/local/include/llvm/ADT/APInt.h:19:
In file included from /usr/local/include/llvm/ADT/ArrayRef.h:14:
/usr/local/include/llvm/ADT/SmallVector.h:232:20: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
  void push_back(T &&Elt) {
                   ^
/usr/local/include/llvm/ADT/SmallVector.h:476:33: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
  iterator insert(iterator I, T &&Elt) {

In file included from toy.cpp:3:
In file included from /usr/local/include/llvm/IR/IRBuilder.h:24:
In file included from /usr/local/include/llvm/IR/Instructions.h:22:
In file included from /usr/local/include/llvm/IR/Attributes.h:20:
In file included from /usr/local/include/llvm/ADT/FoldingSet.h:21:
/usr/local/include/llvm/Support/Allocator.h:134:70: error: expected expression
          BumpPtrAllocatorImpl<AllocatorT, SlabSize, SizeThreshold>> {
                                                                     ^
/usr/local/include/llvm/Support/Allocator.h:346:2: error: expected a type
};

Do you know what would cause these errors?

Thank you!
Joseph

Hi Dan,

So now that the includes are being found building the tutorial results in 74 warnings and 20 errors. Heres a couple examples:

In file included from /usr/local/include/llvm/IR/DerivedTypes.h:21:
In file included from /usr/local/include/llvm/IR/Type.h:19:
In file included from /usr/local/include/llvm/ADT/APFloat.h:20:
In file included from /usr/local/include/llvm/ADT/APInt.h:19:
In file included from /usr/local/include/llvm/ADT/ArrayRef.h:14:
/usr/local/include/llvm/ADT/SmallVector.h:232:20: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
   void push_back(T &&Elt) {
                    ^
/usr/local/include/llvm/ADT/SmallVector.h:476:33: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
   iterator insert(iterator I, T &&Elt) {

You need to build Clang/LLVM with a {CXX, CXXFLAGS} pair (read: a c++ compiler for your host) that supports C++11. That can either be one whose default is c++11, or one that doesn't but lets you put '--std=c++11' in the CXXFLAGS.

Getting Started with the LLVM System — LLVM 15.0.0git documentation suggests GCC >= 4.7.0 for this.

Hello again,

Running gcc —version gets me the following results:

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)

So it looks like I do not have proper GCC installed, I figured that Xcode would have gcc included.

I can see that I am in over my head because I do not know what CXX, CXXFLAGS are and where do you apply them? In make?

In other words what does " put ‘–std=c++11’ in the CXXFLAGS” mean? Do you have an example of what it would look like? or what should I read in order to learn this? I’m happy to read up but I don’t know where to start reading (besides the getting started page on llvm) :slight_smile:

Thank you for your suggestions!
Joseph Morgan

Hi Dan,

So now that the includes are being found building the tutorial results in 74
warnings and 20 errors. Heres a couple examples:

In file included from /usr/local/include/llvm/IR/DerivedTypes.h:21:
In file included from /usr/local/include/llvm/IR/Type.h:19:
In file included from /usr/local/include/llvm/ADT/APFloat.h:20:
In file included from /usr/local/include/llvm/ADT/APInt.h:19:
In file included from /usr/local/include/llvm/ADT/ArrayRef.h:14:
/usr/local/include/llvm/ADT/SmallVector.h:232:20: warning: rvalue references
are a C++11 extension [-Wc++11-extensions]
  void push_back(T &&Elt) {
                   ^
/usr/local/include/llvm/ADT/SmallVector.h:476:33: warning: rvalue references
are a C++11 extension [-Wc++11-extensions]
  iterator insert(iterator I, T &&Elt) {

You need to build Clang/LLVM with a {CXX, CXXFLAGS} pair (read: a c++ compiler
for your host) that supports C++11. That can either be one whose default is
c++11, or one that doesn't but lets you put '--std=c++11' in the CXXFLAGS.

Getting Started with the LLVM System — LLVM 15.0.0git documentation suggests GCC >= 4.7.0 for this.

Hello again,

Running gcc —version gets me the following results:

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr
--with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)

So it looks like I do not have proper GCC installed, I figured that Xcode would
have gcc included.

These days, Xcode ships with Clang (which is a drop-in replacement for GCC, based on LLVM). This should be fine for building TOT Clang/LLVM from source, as long as it is new enough (and I *think* it is).

I can see that I am in over my head because I do not know what CXX, CXXFLAGS are
and where do you apply them? In make?

These are just canonical names for set of flags you pass to a build system (see: Implicit Variables (GNU make) for more examples).

The idea is that you would set the ones that you need when configuring (where the default doesn't quite make sense for your platform)... so I think in your case, you'd want something like this:

../llvm/configure CXX=`which clang++` CXXFLAGS="--std=c++11"

Cheers,

Jon

Hi Dan,

So now that the includes are being found building the tutorial results in 74
warnings and 20 errors. Heres a couple examples:

In file included from /usr/local/include/llvm/IR/DerivedTypes.h:21:
In file included from /usr/local/include/llvm/IR/Type.h:19:
In file included from /usr/local/include/llvm/ADT/APFloat.h:20:
In file included from /usr/local/include/llvm/ADT/APInt.h:19:
In file included from /usr/local/include/llvm/ADT/ArrayRef.h:14:
/usr/local/include/llvm/ADT/SmallVector.h:232:20: warning: rvalue references
are a C++11 extension [-Wc++11-extensions]
void push_back(T &&Elt) {
^
/usr/local/include/llvm/ADT/SmallVector.h:476:33: warning: rvalue references
are a C++11 extension [-Wc++11-extensions]
iterator insert(iterator I, T &&Elt) {

You need to build Clang/LLVM with a {CXX, CXXFLAGS} pair (read: a c++ compiler
for your host) that supports C++11. That can either be one whose default is
c++11, or one that doesn’t but lets you put ‘–std=c++11’ in the CXXFLAGS.

http://llvm.org/docs/GettingStarted.html suggests GCC >= 4.7.0 for this.

Hello again,

Running gcc —version gets me the following results:

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr
–with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)

So it looks like I do not have proper GCC installed, I figured that Xcode would
have gcc included.

These days, Xcode ships with Clang (which is a drop-in replacement for GCC, based on LLVM). This should be fine for building TOT Clang/LLVM from source, as long as it is new enough (and I think it is).

I can see that I am in over my head because I do not know what CXX, CXXFLAGS are
and where do you apply them? In make?

These are just canonical names for set of flags you pass to a build system (see: http://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html#Implicit-Variables for more examples).

The idea is that you would set the ones that you need when configuring (where the default doesn’t quite make sense for your platform)… so I think in your case, you’d want something like this:

…/llvm/configure CXX=which clang++ CXXFLAGS="–std=c++11”

Thanks Jon for your advice. I am still getting the same errors. When I check the cxxflags here’s the output:

Josephs-iMac:~ josephmorgan$ /Users/josephmorgan/build/Debug+Asserts/bin/llvm-config —cxxflags
-I/Users/josephmorgan/llvm/include -I/Users/josephmorgan/build/include -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -g -std=c++11 -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -fno-common -Woverloaded-virtual -Wcast-qual

Josephs-iMac:~ josephmorgan$ /Users/josephmorgan/build/Debug+Asserts/bin/llvm-config --cppflags
-I/Users/josephmorgan/llvm/include -I/Users/josephmorgan/build/include -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS

Josephs-iMac:~ josephmorgan$ /Users/josephmorgan/build/Debug+Asserts/bin/llvm-config --cflags
-I/Users/josephmorgan/llvm/include -I/Users/josephmorgan/build/include -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -g -fno-common

Does that look correct in your opinion?

Thanks again!
Joseph

Hi Joseph,

In other words what does " put '--std=c++11' in the CXXFLAGS” mean? Do you
have an example of what it would look like? or what should I read in order
to learn this? I’m happy to read up but I don’t know where to start reading
(besides the getting started page on llvm) :slight_smile:

You're still trying to build the tutorial right? I assume you
successfully built LLVM already. So if you're building the tutorial
you probably just need this.

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

I see your `llvm-config --cxxflags`` output already has --std=c++11
already in it (your --cppflags does not. I'm not sure why).

I think Jonanthan may have confused you because his suggestion of

../llvm/configure CXX=`which clang++` CXXFLAGS="--std=c++11"

is for configuring and building LLVM/Clang which you've already done.
So you shouldn't need to do that again.

Thanks,

Hi Dan,

Thank for your response.

I have build llvm/clang successfully (meaning it builds without failing). I keep going back to the build though because I somehow think it’s not properly configured.

When I run the following as you suggest:

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

But I continue to get errors as if I am missing C++11:

In file included from /usr/local/include/llvm/IR/DerivedTypes.h:21:
In file included from /usr/local/include/llvm/IR/Type.h:19:
In file included from /usr/local/include/llvm/ADT/APFloat.h:20:
In file included from /usr/local/include/llvm/ADT/APInt.h:19:
In file included from /usr/local/include/llvm/ADT/ArrayRef.h:14:
/usr/local/include/llvm/ADT/SmallVector.h:232:20: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
  void push_back(T &&Elt) {
                   ^
/usr/local/include/llvm/ADT/SmallVector.h:476:33: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
  iterator insert(iterator I, T &&Elt) {

Hi Joseph,

In other words what does " put '--std=c++11' in the CXXFLAGS” mean? Do you
have an example of what it would look like? or what should I read in order
to learn this? I’m happy to read up but I don’t know where to start reading
(besides the getting started page on llvm) :slight_smile:

You're still trying to build the tutorial right? I assume you
successfully built LLVM already. So if you're building the tutorial
you probably just need this.

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

I see your `llvm-config --cxxflags`` output already has --std=c++11
already in it (your --cppflags does not. I'm not sure why).

^^^ I am wondering if perhaps this is my problem?

Hi Joseph,

In other words what does " put '--std=c++11' in the CXXFLAGS” mean? Do you
have an example of what it would look like? or what should I read in order
to learn this? I’m happy to read up but I don’t know where to start reading
(besides the getting started page on llvm) :slight_smile:

You're still trying to build the tutorial right? I assume you
successfully built LLVM already. So if you're building the tutorial
you probably just need this.

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

I see your `llvm-config --cxxflags`` output already has --std=c++11
already in it (your --cppflags does not. I'm not sure why).

Dan, the preprocessor shouldn't need to know about '--std=c++11' right?

Maybe the confusion here is over which one of '--cppflags' vs '--cxxflags' to use where (the former is for the preprocessor, the latter is for the c++ compiler).

Also, looking at an example from earlier in the thread:

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

This suspiciously looks like you're using the just-built llvm-config to give parameters to the system installed clang++. IOW, this could lead you into trouble if `which clang++` doesn't point you to the one in /Users/josephmorgan/build/Release+Assert/bin/ (this really depends on what's on your PATH).

I think Jonanthan may have confused you because his suggestion of

../llvm/configure CXX=`which clang++` CXXFLAGS="--std=c++11"

is for configuring and building LLVM/Clang which you've already done.

Yes, this suggestion is for configuring/building clang... sorry if that added to the confusion.

So you shouldn't need to do that again.

Thanks,

Cheers,
Jon

Just for reference, the option is -std=c++11, single hyphen.

Joerg

In other words what does " put ‘–std=c++11’ in the CXXFLAGS” mean?

Just for reference, the option is -std=c++11, single hyphen.

Joerg

^^ As for the build of LLVM/Clang, I rebuilt with single hyphen as follows :

/Users/josephmorgan/llvm/configure --enable-targets=x86,x86_64 CXX=which clang++ CXXFLAGS="-std=c++11"

And now for the tutorial, somewhere along the line I have used two versions of the following when compiling the tutorial file:

clang++ -g -O3 toy.cpp llvm-config --**cxxflags** --ldflags --libs core -o toy <—this is from http://llvm.org/docs/tutorial/LangImpl3.html see results below:

Undefined symbols for architecture x86_64:
“_del_curterm”, referenced from:
terminalHasColors(int) in libLLVMSupport.a(Process.o)
“_set_curterm”, referenced from:
terminalHasColors(int) in libLLVMSupport.a(Process.o)
“_setupterm”, referenced from:
terminalHasColors(int) in libLLVMSupport.a(Process.o)
“_tigetnum”, referenced from:
terminalHasColors(int) in libLLVMSupport.a(Process.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

clang++ -g -O3 toy.cpp llvm-config --**cppflags** --ldflags --libs core -o toy <—not sure where in this thread I picked this up but see results below:

In file included from toy.cpp:2:
In file included from /usr/local/include/llvm/IR/DerivedTypes.h:21:
In file included from /usr/local/include/llvm/IR/Type.h:19:
In file included from /usr/local/include/llvm/ADT/APFloat.h:20:
In file included from /usr/local/include/llvm/ADT/APInt.h:19:
In file included from /usr/local/include/llvm/ADT/ArrayRef.h:14:
/usr/local/include/llvm/ADT/SmallVector.h:232:20: warning: rvalue references are
a C++11 extension [-Wc++11-extensions]
void push_back(T &&Elt) {

…….Several other errors/warnings

fatal error: too many errors emitted, stopping now [-ferror-limit=]
72 warnings and 20 errors generated.

I appreciate your help!

Joseph Morgan

In other words what does " put '--std=c++11' in the CXXFLAGS” mean?

Just for reference, the option is -std=c++11, single hyphen.

Joerg

^^ As for the build of LLVM/Clang, I rebuilt with single hyphen as follows :
/Users/josephmorgan/llvm/configure --enable-targets=x86,x86_64 CXX=`which
clang++` CXXFLAGS="-std=c++11"

This ^ looks good to me.

And now for the tutorial, somewhere along the line I have used two versions of
the following when compiling the tutorial file:

clang++ -g -O3 toy.cpp `llvm-config --*cxxflags* --ldflags --libs core` -o toy
<—this is from http://llvm.org/docs/tutorial/LangImpl3.html see results below:

Undefined symbols for architecture x86_64:
   "_del_curterm", referenced from:
       terminalHasColors(int) in libLLVMSupport.a(Process.o)
   "_set_curterm", referenced from:
       terminalHasColors(int) in libLLVMSupport.a(Process.o)
   "_setupterm", referenced from:
       terminalHasColors(int) in libLLVMSupport.a(Process.o)
   "_tigetnum", referenced from:
       terminalHasColors(int) in libLLVMSupport.a(Process.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

clang++ -g -O3 toy.cpp `llvm-config --*cppflags* --ldflags --libs core` -o toy
<—not sure where in this thread I picked this up but see results below:

It will help with debugging this to see the output of all of these:

$ echo $PATH
$ pwd
$ find . -name clang++
$ find . -name llvm-config
$ which llvm-config
$ which clang++
$ llvm-config --*cppflags* --ldflags --libs core -v
$ clang++ -g -O3 toy.cpp `llvm-config --cxxflags --ldflags --libs core` -o toy -v

My suspicion is that this is picking the just-built llvm-config and the clang++ is the system provided one. I think you need to use full paths to make sure you're getting *both* of the just-built ones instead.

Jon

Need to link against libterminfo / libtinfo / libncurses, depending on
your platform. Alternatively, disable terminfo support via cmake/configure.

Joerg

Recent versions of llvm-config provide a --system-libs option that will provide this. I don't know why llvm-config provides a separate flag for this, when every pkg-config distribution just puts these in ldflags, but adding the output from this to your build system is the best thing to do.

Unfortunately, old versions of llvm-config don't provide this and produce an error message when you pass it, so you'll need to do a version check in your build system for it too.

David

Thank you all for your input. I can finally compile the tutorial files. Heres what I used for chapter three:

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

Note as Joerg and David suggested, --system-libs is required to link against appropriate libraries.

Also note that --cxxflags is used instead of --cppflags which is opposed to the instructions located on the tutorial page: http://llvm.org/docs/tutorial/LangImpl3.html#full-code-listing

So the question is: Are others required to use these options? If so then is it possible that the documentation is incorrect/incomplete? If the problem is unique to my system, then is it something I did wrong when building LLVM/Clang?

Joseph Morgan

It will help with debugging this to see the output of all of these:

$ echo $PATH
$ pwd
$ find . -name clang++
$ find . -name llvm-config
$ which llvm-config
$ which clang++
$ llvm-config –cppflags --ldflags --libs core -v
$ clang++ -g -O3 toy.cpp llvm-config --cxxflags --ldflags --libs core -o toy -v

My suspicion is that this is picking the just-built llvm-config and the clang++ is the system provided one. I think you need to use full paths to make sure you’re getting both of the just-built ones instead.

Hi Jon,

Using the following: clang++ -g -O3 toy.cpp llvm-config --cxxflags --ldflags --libs core --system-libs -o toy

I was able to compile the tutorial successfully.

Although I have been able to successfully compile the tutorial as I noted in another response to this thread earlier this morning, I wanted to post the output of the commands you suggest. I’m hoping to find out why I have to use apparently “special” options when compiling the tutorial. Here’s the output:

echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

pwd
/Users/josephmorgan

find . -name clang++
./build/Debug+Asserts/bin/clang++

find . -name llvm-config
./build/Debug+Asserts/bin/clang++
find: ./Library/Saved Application State/com.bitrock.installbuilder.savedState: Permission denied

which llvm-config
/usr/local/bin/llvm-config

which clang++
/usr/bin/clang++

llvm-config --cppflags
-I/usr/local/include -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS

llvm-config --ldflags
-L/usr/local/lib

llvm-config --libs core
-lLLVMCore -lLLVMSupport

clang++ -g -O3 toy.cpp llvm-config --cxxflags --ldflags --libs core -o toy -v
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.2.0
Thread model: posix
“/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang” -cc1 -triple x86_64-apple-macosx10.9.0 -emit-obj -disable-free -disable-llvm-verifier -main-file-name toy.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 224.1 -v -g -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/…/lib/clang/5.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /usr/local/include -stdlib=libc++ -O3 -Woverloaded-virtual -Wcast-qual -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/josephmorgan -ferror-limit 19 -fmessage-length 80 -fvisibility-inlines-hidden -stack-protector 1 -mstackrealign -fblocks -fno-rtti -fobjc-runtime=macosx-10.9.0 -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fencode-extended-block-signature -fno-common -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/tb/0bmsh_9179z57k1_hg4m36jr0000gn/T/toy-AtHsw2.o -x c++ toy.cpp
clang -cc1 version 5.0 based upon LLVM 3.3svn default target x86_64-apple-darwin13.2.0
ignoring nonexistent directory “/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/v1”
ignoring nonexistent directory “/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/local/include”
ignoring nonexistent directory “/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/Library/Frameworks”
#include “…” search starts here:
#include <…> search starts here:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/…/lib/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/…/lib/clang/5.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks (framework directory)
End of search list.
“/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld” -demangle -dynamic -arch x86_64 -macosx_version_min 10.9.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -o toy -L/usr/local/lib /var/folders/tb/0bmsh_9179z57k1_hg4m36jr0000gn/T/toy-AtHsw2.o -lLLVMCore -lLLVMSupport -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/…/lib/clang/5.0/lib/darwin/libclang_rt.osx.a

Thank you,

Joseph Morgan