Help with Mac OS X 10.6.2 build

Greetings,
    I am having trouble getting the Kaleidoscope example to build from
tutorial #3 on Mac OS X 10.6.2. I didn't have too much trouble
getting llvm-2.6 and llvm-gcc-frontend to build. Thanks for the help.
Here are the steps I followed:

Environment variables for build
export LLVMOBJDIR=/opt/llvm
export TARGETOPTIONS='--with-arch=nocona --with-tune=generic'
export TRIPLE=i686-apple-darwin9 // I wonder should it be darwin10
export BUILDOPTIONS=LLVM_VERSION_INFO=2.6

Notes for llvm-2.6
cd ~/prog/llvm-2.6
./configure --prefix=/opt/llvm $TARGETOPTIONS --build=$TRIPLE
--host=$TRIPLE --target=$TRIPLE
# I also tried the command below neither seemed to work with example
in tutorial #3
# ./configure --prefix=/opt/llvm
make
make install

Notes for llvm-gcc frontend
Follow the instructions for Darwin/X86 (32- and 64bit support), note
the 32 bit instructions would not compile on 10.6.2:

../llvm-gcc4.2-2.6.source/configure --prefix=`pwd`/../install
--program-prefix=llvm- --enable-llvm=$LLVMOBJDIR
--enable-languages=c,c++$EXTRALANGS $TARGETOPTIONS
--with-gxx-include-dir=/usr/include/c++/4.0.0 --build=$TRIPLE
--host=$TRIPLE --target=$TRIPLE
make $BUILDOPTIONS
make install
ln -sf /usr/lib/libstdc++.6.dylib `pwd`/../install/lib
ln -sf /usr/lib/libstdc++.6.dylib `pwd`/../install/lib/libstdc++.dylib

To build the toy program in the Tutorial I used this command:
g++ -g -O3 toy3.cpp `llvm-config --cppflags --ldflags --libs core` -o toy3

Error that I get:

Tutorial rovitotv$ g++ -g -O3 toy3.cpp `llvm-config --cppflags
--ldflags --libs core` -o toy3
ld: warning: in /opt/llvm/lib/libLLVMCore.a, file is not of required
architecture
ld: warning: in /opt/llvm/lib/libLLVMSupport.a, file is not of
required architecture
ld: warning: in /opt/llvm/lib/libLLVMSystem.a, file is not of required
architecture
Undefined symbols:
  "llvm::SymbolTableListTraits<llvm::Instruction,
llvm::BasicBlock>::addNodeToList(llvm::Instruction*)", referenced
from:
      BinaryExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
      CallExprAST::Codegen() in ccHkdHVT.o
      FunctionAST::Codegen() in ccHkdHVT.o
      llvm::IRBuilder<true,
llvm::ConstantFolder>::InsertHelper(llvm::Instruction*, llvm::Twine
const&) constin ccHkdHVT.o
  "llvm::APFloat::APFloat(double)", referenced from:
      NumberExprAST::Codegen() in ccHkdHVT.o
  "llvm::BasicBlock::BasicBlock(llvm::LLVMContext&, llvm::Twine
const&, llvm::Function*, llvm::BasicBlock*)", referenced from:
      FunctionAST::Codegen() in ccHkdHVT.o
  "llvm::Module::getFunction(llvm::StringRef const&) const", referenced from:
      CallExprAST::Codegen() in ccHkdHVT.o
      PrototypeAST::Codegen() in ccHkdHVT.o
  "llvm::Value::getName() const", referenced from:
      PrototypeAST::Codegen() in ccHkdHVT.o
  "llvm::Function::Function(llvm::FunctionType const*,
llvm::GlobalValue::LinkageTypes, llvm::Twine const&, llvm::Module*)",
referenced from:
      PrototypeAST::Codegen() in ccHkdHVT.o
  "llvm::Instruction::Instruction(llvm::Type const*, unsigned int,
llvm::Use*, unsigned int, llvm::Instruction*)", referenced from:
      llvm::CallInst::CallInst<__gnu_cxx::__normal_iterator<llvm::Value**,
std::vector<llvm::Value*, std::allocator<llvm::Value*> > >

(llvm::Value*, __gnu_cxx::__normal_iterator<llvm::Value**,

std::vector<llvm::Value*, std::allocator<llvm::Value*> > >,
__gnu_cxx::__normal_iterator<llvm::Value**, std::vector<llvm::Value*,
std::allocator<llvm::Value*> > >, llvm::Twine const&,
llvm::Instruction*)in ccHkdHVT.o
  "llvm::Type::getDoubleTy(llvm::LLVMContext&)", referenced from:
      BinaryExprAST::Codegen() in ccHkdHVT.o
      PrototypeAST::Codegen() in ccHkdHVT.o
      PrototypeAST::Codegen() in ccHkdHVT.o
  "llvm::ConstantExpr::getCompare(unsigned short, llvm::Constant*,
llvm::Constant*)", referenced from:
      BinaryExprAST::Codegen() in ccHkdHVT.o
  "llvm::ConstantExpr::getSub(llvm::Constant*, llvm::Constant*)",
referenced from:
      BinaryExprAST::Codegen() in ccHkdHVT.o
  "llvm::Instruction::~Instruction()", referenced from:
      BinaryExprAST::Codegen() in ccHkdHVT.o
      llvm::CmpInst::~CmpInst()in ccHkdHVT.o
      llvm::CmpInst::~CmpInst()in ccHkdHVT.o
      llvm::CallInst::CallInst<__gnu_cxx::__normal_iterator<llvm::Value**,
std::vector<llvm::Value*, std::allocator<llvm::Value*> > >

(llvm::Value*, __gnu_cxx::__normal_iterator<llvm::Value**,

std::vector<llvm::Value*, std::allocator<llvm::Value*> > >,
__gnu_cxx::__normal_iterator<llvm::Value**, std::vector<llvm::Value*,
std::allocator<llvm::Value*> > >, llvm::Twine const&,
llvm::Instruction*)in ccHkdHVT.o
  "llvm::Module::Module(llvm::StringRef const&, llvm::LLVMContext&)",
referenced from:
      _main in ccHkdHVT.o
  "llvm::APFloat::~APFloat()", referenced from:
      NumberExprAST::Codegen() in ccHkdHVT.o
      NumberExprAST::Codegen() in ccHkdHVT.o
  "llvm::Value::dump() const", referenced from:
      vtable for llvm::CmpInstin ccHkdHVT.o
  "llvm::getGlobalContext()", referenced from:
      NumberExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
      PrototypeAST::Codegen() in ccHkdHVT.o
      PrototypeAST::Codegen() in ccHkdHVT.o
      FunctionAST::Codegen() in ccHkdHVT.o
      _main in ccHkdHVT.o
      __static_initialization_and_destruction_0(int, int)in ccHkdHVT.o
  "vtable for llvm::FCmpInst", referenced from:
      BinaryExprAST::Codegen() in ccHkdHVT.o
  "llvm::Type::getForwardedTypeInternal() const", referenced from:
      BinaryExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
      llvm::PATypeHolder::get() constin ccHkdHVT.o
      llvm::PATypeHolder::get() constin ccHkdHVT.o
      llvm::CallInst::CallInst<__gnu_cxx::__normal_iterator<llvm::Value**,
std::vector<llvm::Value*, std::allocator<llvm::Value*> > >

(llvm::Value*, __gnu_cxx::__normal_iterator<llvm::Value**,

std::vector<llvm::Value*, std::allocator<llvm::Value*> > >,
__gnu_cxx::__normal_iterator<llvm::Value**, std::vector<llvm::Value*,
std::allocator<llvm::Value*> > >, llvm::Twine const&,
llvm::Instruction*)in ccHkdHVT.o
  "llvm::CallInst::init(llvm::Value*, llvm::Value* const*, unsigned
int)", referenced from:
      llvm::CallInst::CallInst<__gnu_cxx::__normal_iterator<llvm::Value**,
std::vector<llvm::Value*, std::allocator<llvm::Value*> > >

(llvm::Value*, __gnu_cxx::__normal_iterator<llvm::Value**,

std::vector<llvm::Value*, std::allocator<llvm::Value*> > >,
__gnu_cxx::__normal_iterator<llvm::Value**, std::vector<llvm::Value*,
std::allocator<llvm::Value*> > >, llvm::Twine const&,
llvm::Instruction*)in ccHkdHVT.o
  "llvm::BinaryOperator::Create(llvm::Instruction::BinaryOps,
llvm::Value*, llvm::Value*, llvm::Twine const&, llvm::Instruction*)",
referenced from:
      BinaryExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
  "llvm::Type::isFPOrFPVector() const", referenced from:
      BinaryExprAST::Codegen() in ccHkdHVT.o
  "llvm::Value::setName(llvm::Twine const&)", referenced from:
      BinaryExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
      CallExprAST::Codegen() in ccHkdHVT.o
      PrototypeAST::Codegen() in ccHkdHVT.o
      FunctionAST::Codegen() in ccHkdHVT.o
      llvm::IRBuilder<true,
llvm::ConstantFolder>::InsertHelper(llvm::Instruction*, llvm::Twine
const&) constin ccHkdHVT.o
      llvm::CallInst::CallInst<__gnu_cxx::__normal_iterator<llvm::Value**,
std::vector<llvm::Value*, std::allocator<llvm::Value*> > >

(llvm::Value*, __gnu_cxx::__normal_iterator<llvm::Value**,

std::vector<llvm::Value*, std::allocator<llvm::Value*> > >,
__gnu_cxx::__normal_iterator<llvm::Value**, std::vector<llvm::Value*,
std::allocator<llvm::Value*> > >, llvm::Twine const&,
llvm::Instruction*)in ccHkdHVT.o
  "llvm::AttrListPtr::~AttrListPtr()", referenced from:
      llvm::CallInst::CallInst<__gnu_cxx::__normal_iterator<llvm::Value**,
std::vector<llvm::Value*, std::allocator<llvm::Value*> > >

(llvm::Value*, __gnu_cxx::__normal_iterator<llvm::Value**,

std::vector<llvm::Value*, std::allocator<llvm::Value*> > >,
__gnu_cxx::__normal_iterator<llvm::Value**, std::vector<llvm::Value*,
std::allocator<llvm::Value*> > >, llvm::Twine const&,
llvm::Instruction*)in ccHkdHVT.o
  "llvm::ReturnInst::ReturnInst(llvm::LLVMContext&, llvm::Value*,
llvm::Instruction*)", referenced from:
      FunctionAST::Codegen() in ccHkdHVT.o
  "llvm::ConstantExpr::getCast(unsigned int, llvm::Constant*,
llvm::Type const*)", referenced from:
      BinaryExprAST::Codegen() in ccHkdHVT.o
  "llvm::Module::dump() const", referenced from:
      _main in ccHkdHVT.o
  "llvm::ConstantExpr::getMul(llvm::Constant*, llvm::Constant*)",
referenced from:
      BinaryExprAST::Codegen() in ccHkdHVT.o
  "vtable for llvm::CallInst", referenced from:
      llvm::CallInst::CallInst<__gnu_cxx::__normal_iterator<llvm::Value**,
std::vector<llvm::Value*, std::allocator<llvm::Value*> > >

(llvm::Value*, __gnu_cxx::__normal_iterator<llvm::Value**,

std::vector<llvm::Value*, std::allocator<llvm::Value*> > >,
__gnu_cxx::__normal_iterator<llvm::Value**, std::vector<llvm::Value*,
std::allocator<llvm::Value*> > >, llvm::Twine const&,
llvm::Instruction*)in ccHkdHVT.o
  "llvm::User::operator new(unsigned long, unsigned int)", referenced from:
      BinaryExprAST::Codegen() in ccHkdHVT.o
      CallExprAST::Codegen() in ccHkdHVT.o
      PrototypeAST::Codegen() in ccHkdHVT.o
      FunctionAST::Codegen() in ccHkdHVT.o
  "llvm::Type::getInt1Ty(llvm::LLVMContext&)", referenced from:
      BinaryExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
  "llvm::ConstantExpr::getAdd(llvm::Constant*, llvm::Constant*)",
referenced from:
      BinaryExprAST::Codegen() in ccHkdHVT.o
  "llvm::CastInst::Create(llvm::Instruction::CastOps, llvm::Value*,
llvm::Type const*, llvm::Twine const&, llvm::Instruction*)",
referenced from:
      BinaryExprAST::Codegen() in ccHkdHVT.o
  "llvm::verifyFunction(llvm::Function const&,
llvm::VerifierFailureAction)", referenced from:
      FunctionAST::Codegen() in ccHkdHVT.o
  "llvm::User::operator delete(void*)", referenced from:
      BinaryExprAST::Codegen() in ccHkdHVT.o
      llvm::CmpInst::~CmpInst()in ccHkdHVT.o
  "llvm::Function::arg_size() const", referenced from:
      CallExprAST::Codegen() in ccHkdHVT.o
      PrototypeAST::Codegen() in ccHkdHVT.o
  "llvm::VectorType::get(llvm::Type const*, unsigned int)", referenced from:
      BinaryExprAST::Codegen() in ccHkdHVT.o
  "llvm::Function::BuildLazyArguments() const", referenced from:
      PrototypeAST::Codegen() in ccHkdHVT.o
  "llvm::FunctionType::get(llvm::Type const*, std::vector<llvm::Type
const*, std::allocator<llvm::Type const*> > const&, bool)", referenced
from:
      PrototypeAST::Codegen() in ccHkdHVT.o
  "llvm::sys::AtomicIncrement(unsigned int volatile*)", referenced from:
      BinaryExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
      llvm::Type::addRef() constin ccHkdHVT.o
      llvm::PATypeHolder::addRef() in ccHkdHVT.o
      llvm::PATypeHolder::get() constin ccHkdHVT.o
      llvm::PATypeHolder::get() constin ccHkdHVT.o
      llvm::CallInst::CallInst<__gnu_cxx::__normal_iterator<llvm::Value**,
std::vector<llvm::Value*, std::allocator<llvm::Value*> > >

(llvm::Value*, __gnu_cxx::__normal_iterator<llvm::Value**,

std::vector<llvm::Value*, std::allocator<llvm::Value*> > >,
__gnu_cxx::__normal_iterator<llvm::Value**, std::vector<llvm::Value*,
std::allocator<llvm::Value*> > >, llvm::Twine const&,
llvm::Instruction*)in ccHkdHVT.o
  "typeinfo for llvm::Instruction", referenced from:
      typeinfo for llvm::CmpInstin ccHkdHVT.o
  "llvm::CmpInst::CmpInst(llvm::Type const*,
llvm::Instruction::OtherOps, unsigned short, llvm::Value*,
llvm::Value*, llvm::Twine const&, llvm::Instruction*)", referenced
from:
      BinaryExprAST::Codegen() in ccHkdHVT.o
  "llvm::ConstantFP::get(llvm::LLVMContext&, llvm::APFloat const&)",
referenced from:
      NumberExprAST::Codegen() in ccHkdHVT.o
  "llvm::sys::AtomicDecrement(unsigned int volatile*)", referenced from:
      BinaryExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
      llvm::Type::dropRef() constin ccHkdHVT.o
      llvm::PATypeHolder::get() constin ccHkdHVT.o
      llvm::PATypeHolder::get() constin ccHkdHVT.o
      llvm::CallInst::CallInst<__gnu_cxx::__normal_iterator<llvm::Value**,
std::vector<llvm::Value*, std::allocator<llvm::Value*> > >

(llvm::Value*, __gnu_cxx::__normal_iterator<llvm::Value**,

std::vector<llvm::Value*, std::allocator<llvm::Value*> > >,
__gnu_cxx::__normal_iterator<llvm::Value**, std::vector<llvm::Value*,
std::allocator<llvm::Value*> > >, llvm::Twine const&,
llvm::Instruction*)in ccHkdHVT.o
  "llvm::Type::destroy() const", referenced from:
      BinaryExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
      BinaryExprAST::Codegen() in ccHkdHVT.o
      llvm::Type::dropRef() constin ccHkdHVT.o
      llvm::PATypeHolder::get() constin ccHkdHVT.o
      llvm::PATypeHolder::get() constin ccHkdHVT.o
      llvm::CallInst::CallInst<__gnu_cxx::__normal_iterator<llvm::Value**,
std::vector<llvm::Value*, std::allocator<llvm::Value*> > >

(llvm::Value*, __gnu_cxx::__normal_iterator<llvm::Value**,

std::vector<llvm::Value*, std::allocator<llvm::Value*> > >,
__gnu_cxx::__normal_iterator<llvm::Value**, std::vector<llvm::Value*,
std::allocator<llvm::Value*> > >, llvm::Twine const&,
llvm::Instruction*)in ccHkdHVT.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Hi,

Try these scripts to build llvm and llvm-gcc. It's the ones I use and I managed to get them to work when I saw another build script using those CFLAGS.

They compile llvm and stuff using only x86_64, but you can then generate code for i386 (just use a different backend). The configuration options are at the top of the scripts and they install llvm and llvm-gcc to ~/llvm.

Regards,

   Filipe

install-llvm (896 Bytes)

install-llvm-gcc (1.29 KB)

Filipe,
    Thanks for the help! I am getting a configure error with llvm-2.6
now. Here is what I got:

echo $TARGETS
host,x86,x86_64,cpp
Todd-Rovitos-MacBook:llvm-2.6-build rovitotv$ ../llvm-2.6/configure
--prefix=/opt/llvm/ --enable-bindings=none --enable-targets=$TARGETS
--enable-optimized --with-llvmgccdir=/opt/llvm/
--with-llvm-externals=/opt

I get the following configure error:
configure: error: Unrecognized target host

It appears 'host' is not a valid target for 2.6, are your scripts for
2.6? Thanks again.

Filipe,
   Thanks again for your scripts. I did get them to work for LLVM 2.6
attached are the very minor changes. In the end I added -arch to the
install-llvm and removed the flags from install-llvm-gcc. Not sure
why this worked but now the Tutorial stuff seems to work. Without
your scripts I don't think I would of gotten it built and running.
Thanks again!

install-llvm (1.29 KB)

install-llvm-gcc (1.3 KB)

Looks like you've gotten things up and running, which is excellent. Just for reference, then, here's a bit more info about what may have been causing the issues originally.

These sorts of errors are most commonly due to a mismatch of 64-bit vs. 32-bit slices. I.e., your libraries are built 32-bit and you're linking against a 64-bit program, or vice-versa. You can use otool to look at the mach-o headers for the files and see how they're built. "otool -vf filename" will show the fat headers (with slice types) for a fat binary, and "otool -vh" will show the header for a thin binary. Try the former, and if it doesn't give any output, you have a thin binary and should use the latter.

-Jim

Hi.

My scripts were for LLVM HEAD (I never used a point release :wink: ). Try removing the "host" target... maybe that was only added recently, to allow not changing build scripts while making sure the "host" code emitter was there.

Regards,

   Filipe