LLVM ERROR: Program used external function 'X.foo' which could not be resolved!

Hi,

I have this module:

; ModuleID = './executableModule'

@typeInfo0 = constant { i32 } zeroinitializer
@typeInfo1 = constant { i32 } { i32 1 }
@typeInfo2 = constant { i32 } { i32 2 }
@typeInfo3 = constant { i32 } { i32 3 }
@typeInfo4 = constant { i32 } { i32 4 }
@typeInfo5 = constant { i32 } { i32 5 }
@typeInfo6 = constant { i32 } { i32 6 }

declare void @print32Int(i32, i8*)

declare void @print64Int(i64, i8*)

declare void @printStr(i8*)

declare void @throwCppException(i32)

declare void @deleteOurException(i8*)

declare i8* @createOurException(i32)

declare i32 @_Unwind_RaiseException(i8*) noreturn

declare i32 @_Unwind_Resume(i8*) noreturn

declare i32 @ourPersonality(i32, i32, i64, i8*, i8*)

declare i32 @llvm.eh.typeid.for(i8*) nounwind readnone

define i32 @Y.foo2(i32) {
  %h = alloca i32
  %g = alloca i32
  %bar = alloca i32
  store i32 %0, i32* %bar
  %"argument read" = load i32* %bar
  %"Code::Op::Mul" = mul i32 %"argument read", 5
  store i32 %"Code::Op::Mul", i32* %g
  %read = load i32* %g
  %"calling function" = call i32 @X.foo(i32 %read)
  store i32 %"calling function", i32* %h
  %"argument read1" = load i32* %bar
  %read2 = load i32* %h
  %addtmp = add i32 %"argument read1", %read2
  ret i32 %addtmp
}

define i32 @X.foo(i32) {
  %g = alloca i32
  %bar = alloca i32
  store i32 %0, i32* %bar
  %"argument read" = load i32* %bar
  %addtmp = add i32 %"argument read", 2
  store i32 %addtmp, i32* %g
  %"argument read1" = load i32* %bar
  %read = load i32* %g
  %"Code::Op::Mul" = mul i32 %"argument read1", %read
  ret i32 %"Code::Op::Mul"
}

I try to grab a function from it by this code

dumpModulesToBitcodeFile( std::string("./executableModule"), llvmModule);
llvm::Function* result = llvmModule->getFunction("X.foo");
OurFPM = new llvm::FunctionPassManager(llvmModule);
llvm::EngineBuilder eB(llvmModule);
eB.setEngineKind(llvm::EngineKind::JIT);
llvmEngine = eB.create();

but it fails at the next line:

llvmEngine->getPointerToFunction(result);

with this error

LLVM ERROR: Program used external function 'X.foo' which could not be resolved!

I don't have any idea why this is failing, as it should be clear from
the code, i'm running the bitcode dump just before the function grab,
and the 'X.foo' function is clearly present in the module

any ideas? i'm using llvm-3.1