Query regarding CallInst::Create

Hello,

I have been trying to plugin a function into a loop using a LoopPass.
However, I get the error:

Referencing function in another module!
%2 = call i32 @test_print()

and eventually a coredump.

Details are as follows:
There is a function called int test_print() {…}

It is being declared in the module using:

func = mod->getOrInsertFunction(“test_print”, Type::getInt32Ty(ctx), (Type*)0);
f = cast(func);

The call instruction is being inserted using:

Instruction *newInst = CallInst::Create(f, “”, topInst);

Any help wrt this error would be really appreciated.
Thanks.

PS: Though similar, this is different from http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-August/042845.html as I do not make use of builder.