views:

46

answers:

1

I have recently started experimenting with LLVM under MinGW. I have read the Kaleidoscope tutorial but now I'm having problems with external functions.

I'm declaring external functions like this:

const Type* doubleType = Type::getPrimitiveType(ctx, Type::DoubleTyID);
std::vector<const Type*> doubleParams;
doubleParams.push_back(doubleType);
FunctionType* doubleDouble = FunctionType::get(doubleType, doubleParams, false);
Function* SinFunction = Function::Create(doubleDouble, Function::ExternalLinkage, "sin", mod);

Where mod is the Module* and ctx is the LLVMContext&.

In this case, everything works properly. However, if I declare a function:

extern "C"
double my_cubic_transform(double x) {
    return x*x*x;
}

And change the SinFunction declaration from using "sin" to using "my_cubic_transform"(without changing anything else), then I get:

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

Changing my makefile to include the "-g" option no effect. The Kaleidoscope tutorial suggested this was possible in LLVM(at least for JIT, which I am using). So am I doing something wrong? If so, what?

+1  A: 

Never mind, I figured it out.

Turns out that even though I am using an executable(exe) and not a dll, I have to declare my_cubic_transform with __declspec(dllexport).

Whoever wrote the tutorial must've used some other platform where __declspec doesn't exist and therefore didn't find this problem.

luiscubal
Yeah, probably any platform other than windows :)
jer