【问题标题】:How to include the 'xxx_stub.h' file generated from a haskell source file when building with Stack使用 Stack 构建时如何包含从 haskell 源文件生成的“xxx_stub.h”文件
【发布时间】: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


【解决方案1】:

如果 Stack 有一些适当的方法来做这件事,我真的很喜欢它,但 AFAIK 它没有。

我目前在一个具有类似要求的项目中所做的是,我不是复制 _stub.h 文件到更方便的位置,而是符号链接它。只需执行一次,符号链接可以置于版本控制之下,然后对LONG_PATH/....h 文件的更新将自动显示在便利文件中。

$ ln -s dist/build/bla/bla/long/path/MyLib_stub.h app/MyLib_stub.h
$ git add app/MyLib_stub.h

恐怕这不适用于 Windows,但可能有类似的替代方案。

【讨论】:

  • 谢谢。这足够聪明和方便。但是当我 git clone 将项目从 ubuntu 转移到 mac 时,我必须再次设置这个符号链接,因为它不再是 x86_64-linux。只是想知道是否有任何 auto-variable 供 Stack 引用其 build/ 路径。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-26
  • 2014-08-21
  • 2011-09-11
  • 2022-10-13
  • 2013-04-19
  • 2011-01-22
相关资源
最近更新 更多