The first two lines of llvm tutorial don't compile.

I took the first two lines of the sample program in the tutorial:

hendrik@lovesong:~/dv/lang/hlvm$ cat broken.cpp
#include "llvm/DerivedTypes.h"
#include "llvm/Module.h"
hendrik@lovesong:~/dv/lang/hlvm$

and tried to compile them using the llvm-dev in Debian testing:

hendrik@lovesong:~/dv/lang/hlvm$ g++ -o broken.o -c broken.cpp
In file included from /usr/include/llvm/Type.h:16,
                 from /usr/include/llvm/DerivedTypes.h:21,
                 from broken.cpp:1:
/usr/include/llvm/Support/DataTypes.h:38:3: error: #error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
hendrik@lovesong:~/dv/lang/hlvm$

Did I do something wrong, or is something broken? In llvm or in g++?

hendrik@lovesong:~/dv/lang/hlvm$ g++ --version
g++ (GCC) 4.2.4 (Debian 4.2.4-1)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

hendrik@lovesong:~/dv/lang/hlvm$

-- hendrik

You need to use the script 'llvm-config' to pass correct arguments to g++:

g++ -o broken.o `llvm-config --cxxflags` broken.cpp

The #error is unfortunate. It all comes about because the C standards committee tried to define C++ and they got it wrong. Then this wrong concept was burned into stdint.h, for poor project folks to deal with.

From the header itself:

// Note that this header's correct operation depends on __STDC_LIMIT_MACROS
// being defined. We would define it here, but in order to prevent Bad Things
// happening when system headers or C++ STL headers include stdint.h before
// we define it here, we define it on the g++ command line (in Makefile.rules).
#if !defined(__STDC_LIMIT_MACROS)
# error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
#endif

So, for now, it looks like you have to define the on the command line. :frowning:

This code is bogus however, working stdint.h files don't need this defined and checking it like this is wrong.

Interesting. When I type the command as you provided it (using cut-and-paste) I get:

hendrik@lovesong:~/dv/lang/hlvm$ g++ -o broken.o `llvm-config --cxxflags` broken.cpp
g++: (Debian: No such file or directory
g++: 2.2-7): No such file or directory
hendrik@lovesong:~/dv/lang/hlvm$

So I execute the script by itself, and get

hendrik@lovesong:~/dv/lang/hlvm$ llvm-config --cxxflags
-I/usr/include/llvm -D_DEBUG -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -O2 -fomit-frame-pointer -DLLVM_DEBIAN_INFO= (Debian 2.2-7) -Woverloaded-virtual
hendrik@lovesong:~/dv/lang/hlvm$

Putting that output into the command, and removing the
-DLLVM_DEBIAN_INFO= (Debian 2.2-7) from it, things work
as well as one might expect for a program without main():

hendrik@lovesong:~/dv/lang/hlvm$ g++ -o broken.o -I/usr/include/llvm -D_DEBUG -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -O2 -fomit-frame-pointer -Woverloaded-virtual broken.cpp/usr/lib/gcc/i486-linux-gnu/4.2.4/../../../../lib/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
hendrik@lovesong:~/dv/lang/hlvm$

Do you suppose a bug should be logged against the Debian package?

-- hendrik

I've seen this (or something similar) happen before on Darwin. The issue is that something, either inside llvm-config or in the script that generates llvm-config should be putting quotes around the parameters in quotes.

--Owen

Looks that way. I build LLVM from subversion on my Ubuntu desktop and I
don't see that flag:

thudson@thudson:~$ llvm-config --cxxflags
-I/usr/local/include -D_DEBUG -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -O3
-fomit-frame-pointer -Woverloaded-virtual

OK. Done.

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=484153

-- hendrik

The Debian package llvm-dev also appears to be lacking the IRBuilder.h
include file! Would anything much work without it? I think I'll write
Debian llvm-dev off.

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=484220

Now compiling from svn.

-- hendrik

The Debian package llvm-dev also appears to be lacking the IRBuilder.h
include file!

Right, because Debian includes llvm 2.2 and file was renamed after 2.2
release. Tutorial reflects LLVM TOT.

And I was using the online documentation instead of the Debian llvm-doc
package, which has a link to /usr/share/doc/llvm-doc/html/tutorial/, but
the file does not exist.

-- hendrik