【发布时间】:2018-10-19 06:39:08
【问题描述】:
使用 Stack 构建,我在 src/ 中有一个 lib.hs,在 app/ 中有一个 main.c。构建时在.stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build下生成lib_stub.h。
要将此文件包含在main.c 中,我要么在#include 指令后面写一个完整的绝对路径,要么在手动第二遍之前,手动将lib_stub.h 文件复制到app/,这有点愚蠢.
有没有更好的办法?
更多信息:
我的package.yaml 看起来像
name: mylib
version: 0.1.0.0
github: "gituser/mylib"
license: BSD3
author: "Author name here"
maintainer: "example@example.com"
copyright: "2018 Author name here"
extra-source-files:
- README.md
- ChangeLog.md
# Metadata used when publishing your package
# synopsis: Short description of your package
# category: Web
# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description: Please see the README on GitHub at <https://github.com/gituser/mylib#readme>
dependencies:
- base >= 4.7 && < 5
library:
source-dirs: src
dependencies:
- free
- mtl
executables:
cont-demo:
main: main.c
source-dirs: app
ghc-options:
- -threaded
# - -rtsopts
# - -with-rtsopts=-N
dependencies:
- mylib
tests:
mylib-test:
main: Spec.hs
source-dirs: test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- mylib
我的路径结构看起来像
.
├── app
│ ├── MyLib_stub.h
│ └── main.c
├── ChangeLog.md
├── mylib.cabal
├── LICENSE
├── package.yaml
├── README.md
├── Setup.hs
├── src
│ └── MyLib.hs
├── stack.yaml
└── test
└── Spec.hs
app/MyLib_stub.h 是手动复制的,而不是自动放置在那里。
【问题讨论】:
-
也许您想将包含文件的路径作为参数传递给您最喜欢的编译器?
-
但是如果我的项目被移动到另一个路径,包含路径可能会有所不同。例如,当 'git clone' 被另一个人编辑时,这可能会发生。
-
@arrowd 我只是将
main.c文件放到app/中,然后编辑package.yaml以获得类似main: main.c的条目。 Stack 设法为我构建了main.c。我没有想太多。
标签: c haskell build ffi haskell-stack