如何通过ghc只获取没有main函数的目标文件?

发布于 2024-09-14 15:50:51 字数 367 浏览 2 评论 0原文

[源代码]

数据 FooBar = Foo |酒吧

[命令]

$ ghc -c foo_bar.hs
foo_bar.hs:1:0: 模块“Main”中未定义函数“main”

[Configuration]

Glasgow Haskell 编译器,版本 6.12.3,适用于 Haskell 98,第 2 阶段,由 GHC 引导 版本6.10.4

[Source Code]

data FooBar = Foo | Bar

[Command]

$ ghc -c foo_bar.hs
foo_bar.hs:1:0: The function 'main' is not defined in module 'Main'

[Configuration]

Glasgow Haskell Compiler, Version 6.12.3, for Haskell 98, stage 2 booted by GHC
version 6.10.4

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

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

发布评论

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

评论(1

九八野马 2024-09-21 15:50:51

您应该在模块中定义类型,然后编译它:

module Test where
data FooBar = Foo | Bar

通过调用 ghc -c foo_bar.hs ,将生成目标文件 foo_bar.o ,而无需定义主要

You should define your type in a module, and then compile it:

module Test where
data FooBar = Foo | Bar

By invoking ghc -c foo_bar.hs, the object file foo_bar.o will be generated without having to define main.

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