0

I am just getting started with llvm.

Here's code I am trying to compile:

#include <stdio.h>
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/IRBuilder.h"


int main()
{
  llvm::LLVMContext& context = llvm::getGlobalContext();
  llvm::Module* module = new llvm::Module("top", context);
  llvm::IRBuilder<> builder(context); 

  module->dump( );
}

when i compile with :

llvm-g++ try.cpp  -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS `llvm-config --cxxflags --ldflags --libs`

I get the a.out file. No worries.

But, I am interested in getting the LLVM IR file.So, I compiled with

llvm-g++ try.cpp  -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -S -emit-llvm 
lli try.s

I get an error saying

LLVM ERROR: Program used external function '_ZN4llvm16getGlobalContextEv' which could not be resolved!

The command :

llvm-g++ try.cpp  -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS `llvm-config --cxxflags --ldflags --libs` -S -emit-llvm

leaves me with several warnings and when i execute the resultant .s file with lli , I get the same error as before.

Thanks a lot for your help

user1423561
  • 327
  • 1
  • 3
  • 18
  • I just answered your other question, and found this one which gives more details about your issue. However, I managed to get this program working with clang ver. 3.3, using exactly the command line I gave in my answer. Which version of llvm do you use? – didierc Aug 04 '14 at 22:29
  • Hi didierc.I use llvm 3.4.2. I want to generate the .s file. How do i do it ? – user1423561 Aug 05 '14 at 06:00
  • See my updated answer to the other question. My system sports a `clang++` program rather than `llvm-g++`, and I used `--cppflags` instead of `--cxxflags`, but otherwise it should be the same. The `-D` defines are actually generated by `llvm-config`, you don't need to write them explicitely. – didierc Aug 05 '14 at 06:24

0 Answers0