LLVM 外部函数

发布于 2024-09-08 06:31:25 字数 989 浏览 4 评论 0原文

我最近开始在 MinGW 下尝试 LLVM。我已阅读 万花筒 教程,但现在我在使用外部函数时遇到问题。

我声明的外部函数如下:

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);

其中 mod 是 Module*,ctx 是 LLVMContext&。

在这种情况下,一切正常。 但是,如果我声明一个函数:

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

并将 SinFunction 声明从使用“sin”更改为使用“my_cubic_transform”(不更改其他任何内容),那么我得到:

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

更改我的 makefile 以包含“-g”选项无效。 万花筒教程建议这在 LLVM 中是可能的(至少对于我正在使用的 JIT 来说)。那么我做错了什么吗?如果是这样,那又怎样?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧瑾黎汐 2024-09-15 06:31:25

没关系,我已经弄清楚了。

事实证明,即使我使用的是可执行文件(exe)而不是 dll,我也必须使用 __declspec(dllexport) 声明 my_cubic_transform。

编写本教程的人一定使用过 __declspec 不存在的其他平台,因此没有发现这个问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文