- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果您declare a library + executable sections in a cabal file while avoiding double compilation of the library通过将库放入 hs-source-dirs
目录中,您通常无法再使用 ghci
和 runhaskell
运行项目,特别是如果可执行文件本身有辅助模块。
推荐的项目布局是什么
runhaskell
最佳答案
假设您有一个 mylib
库、mylib-commandline
和 mylib-server
可执行文件。
您对库和每个可执行文件使用hs-source-dirs
,以便每个可执行文件都有自己的项目根目录,从而避免双重编译:
mylib/ # Project root
mylib.cabal
src/ # Root for the library
tests/
mylib-commandline/ # Root for the command line utility + helper modules
mylib-server/ # Root for the web service + helper modules
完整目录布局:
mylib/ # Project root
mylib.cabal
src/ # Root for the library
Web/
Mylib.hs # Main library module
Mylib/
ModuleA # Mylib.ModuleA
ModuleB # Mylib.ModuleB
tests/
...
mylib-commandline/ # Root for the command line utility
Main.hs # "module Main where" stub with "main = Web.Mylib.Commandline.Main.main"
Web/
Mylib/
Commandline/
Main.hs # CLI entry point
Arguments.hs # Programm command line arguments parser
mylib-server/ # Root for the web service
Server.hs # "module Main where" stub with "main = Web.Mylib.Server.Main.main"
Web/
Mylib/
Server/
Main.hs # Server entry point
Arguments.hs # Server command line arguments parser
类似 stub 入口点文件mylib-commandline/Main.hs
如下所示:
module Main where
import qualified Web.Mylib.Server.Main as MylibServer
main :: IO ()
main = MylibServer.main
您需要它们,因为可执行文件
必须在名为Main
的模块上启动。
你的mylib.cabal
看起来像这样:
library
hs-source-dirs: src
exposed-modules:
Web.Mylib
Web.Mylib.ModuleA
Web.Mylib.ModuleB
build-depends:
base >= 4 && <= 5
, [other dependencies of the library]
executable mylib-commandline
hs-source-dirs: mylib-commandline
main-is: Main.hs
other-modules:
Web.Mylib.Commandline.Main
Web.Mylib.Commandline.Arguments
build-depends:
base >= 4 && <= 5
, mylib
, [other depencencies for the CLI]
executable mylib-server
hs-source-dirs: mylib-server
main-is: Server.hs
other-modules:
Web.Mylib.Server.Main
build-depends:
base >= 4 && <= 5
, mylib
, warp >= X.X
, [other dependencies for the server]
cabal build
将构建库和两个可执行文件,而无需对库进行双重编译,因为每个文件都位于自己的 hs-source-dirs
中,并且可执行文件依赖于图书馆。
您仍然可以使用 runghc
从项目根运行可执行文件,使用 -i
开关来告诉它应在哪里查找模块(使用 :
作为分隔符):
runhaskell -isrc:mylib-commandline mylib-commandline/Main.hs
runhaskell -isrc:mylib-server mylib-server/Server.hs
这样,您就可以拥有干净的布局、带有帮助程序模块的可执行文件,并且一切仍然可以与 runhaskell
/runghc
和 ghci
一起使用。为了避免重复输入此标志,您可以添加类似的内容
:set -isrc:mylib-commandline:mylib-server
到您的.ghci
文件。
请注意,有时应该将代码拆分为单独的包,例如mylib
、mylib-commandline
和 mylib-server
。
关于haskell - 如何使用库+可执行文件创建一个仍然使用 runhaskell/ghci 运行的 Haskell cabal 项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12305970/
所以问题是:如何使用标准 C 库以跨平台方式实现简单的自检可执行文件? 在这里,我正在寻找技术,而不是特定的检查方法(如 CRC 或哈希码),但该技术可能包含更适合某些方法的元素(例如见下文)。 目的
我想构建一个 C++ 可执行文件,以便所有库也附加到可执行文件。构建这样一个可执行文件的方法是什么?因此,每当我在其他 PC(运行 Ubuntu)上使用 g++ 编译我的代码时,它不需要运行该可执行文
我在 Netbeans IDE 8.0.1 中编写了一个名为 SampleChat 的 Java GUI 程序,并使用“clean and build”功能创建了一个 jar 文件。 我进入 Netb
我有两个 DLL,一个用 native C++ 编写,另一个用 C++/CLI 编写。前者被注入(inject)到进程中,并在稍后的时间点加载后者。在调试时,我注意到 native DLL 的断点运行
如何访问可执行文件的机器代码(二进制文件)? 详情 我使用的是 Ubuntu (Linux) 我想访问 .exe 文件(文件遵循 PE 格式)的机器代码(二进制文件) 我正在使用 C 来实现 最佳答案
这个问题在这里已经有了答案: Run java jar file on a server as background process (4 个回答) 关闭1年前. 我正在使用命令提示符运行一个可执行
我的 jar 没有运行,我可以告诉它尝试运行,因为 log4j 文件设法创建日志文件夹,但没有任何 react 并且日志为空白。 我的问题是我在名为 bin 的文件夹中有 jar 文件,在名为 lib
我正在为我教育第一学期的编程考试创建一个程序。它应该向用户显示哥本哈根和其他 6 个城市(在其他时区)的时间。用户还应该能够将城市添加到列表中。我正在用 JAVA 编写程序(下面提供源代码)。当我从
我正在查看雅虎的 YUI 压缩器可执行 jar,他们有这个类,从 list 文件链接为“主类”: package com.yahoo.platform.yui.compressor; import j
问题是:从 Eclipse 导出时可执行 jar 中包含什么?我问这个问题是因为我想知道,例如,如果我在项目根目录中有一个图像,该图像是否会包含在导出中? 澄清:我说的是可运行的 jar 文件(已编辑
我知道这个问题已经被问了很多,并且我已经尝试了 eclipse(Kepler、Ganymede、Galileo)、fatJar、netbeans、blueJ、命令行和手册中的大约 20-30 种不同的
我从 IntelliJ 14.03 中的一个工件构建了一个 .jar。当我尝试在 JRE 中打开它时,没有任何反应。这只是一个简单的 GUI。 提前致谢。 最佳答案 在jar位置运行命令,例如 jav
我使用 eclipse 创建了一个可执行 JAR 文件。我在项目文件夹中有资源当框架打开时不会出现。我的意思是当我双击 JAR 文件时。更多的所以,在我尝试删除 JAR 文件后,我收到一条警告,表明该
我创建了一个尺寸相当大(125,000 kb)的可运行 Jar 文件。当我运行它时,该 jar 文件内的应用程序不会显示,但在任务管理器中 javaw.exe(应链接到该 jar 文件)进程正在运行。
我已经使用 Eclipse(文件->导出)为我的 java 程序创建了一个可执行 jar 文件。 当我双击 jar 时,它工作正常。将 jar 文件复制到另一台计算机(Windows)后,我收到错误“
我用 eclipse indigo 创建了一个可执行的 jar 文件,但是当我双击它时什么也没有发生。但是当我将 java -jar c:/dir/filename.jar 写入 cmd 时,它可以工
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭10 年前。 Improve th
如何让该 Java 代码在 Eclipse 之外运行? import java.util.*; public class Calculations { public static void main(
今天我第一次启动 jar 文件时遇到问题。现在我知道(解压 jar 后)当我在 Eclipse 中导出并创建程序的 jar 包时,文本文件并没有出现。 为什么文本文件没有与类文件一起出现?我应该将它们
我不知道为什么,但是当我将项目导出到可执行 jar 文件时,有些东西并不像从 eclipse 运行程序一样。一帧不会打开,其中只包含文本。我有另一个内部框架,它是一个分割 Pane ,包含右侧面板上的
我是一名优秀的程序员,十分优秀!