如何解决无法在 NixOS 上构建 haskell 包 mysql
我正在尝试使用使用 cabal-3.2.0.0
的 ghc-8.2.2
、MysqL-0.1.7.3
构建最基本的 haskell 项目。
我使用 cabal init
设置项目,将 MysqL ^>= 0.1.7
添加到 .cabal
文件。然后我还添加了这个 shell.nix
文件以将库依赖项引入范围:
所以我添加了一个 shell.nix
文件来明确地将所有内容纳入范围:
(这源自here)
let
oldpkgs=import (fetchTarball https://github.com/NixOS/nixpkgs/archive/83b35508c6491103cd16a796758e07417a28698b.tar.gz) {};
pkgs=import <nixpkgs>{};
ghc = oldpkgs.haskell.compiler.ghc822;
in pkgs.haskell.lib.buildStackProject {
inherit ghc;
name = "myEnv";
buildInputs = (with oldpkgs; [ zlib MysqL openssl ]);
}
我输入了 nix-shell
并尝试使用 cabal build --with-compiler ghc-8.2.2
构建项目。但是,我收到此错误而不是构建成功:
[...]
Failed to build MysqL-0.1.7.3.
Build log (
/home/faebl/.cabal/logs/ghc-8.2.2/MysqL-0.1.7.3-7b08cf393638283e9449be836b946cd61b6404d2e6bc263d439034d2df46d924.log
):
[1 of 1] Compiling Main ( /home/faebl/dev/MysqLTest/dist-newstyle/tmp/src-1662897/MysqL-0.1.7.3/dist/setup/setup.hs,/home/faebl/dev/MysqLTest/dist-newstyle/tmp/src-1662897/MysqL-0.1.7.3/dist/setup/Main.o )
Linking /home/faebl/dev/MysqLTest/dist-newstyle/tmp/src-1662897/MysqL-0.1.7.3/dist/setup/setup ...
Configuring MysqL-0.1.7.3...
Preprocessing library for MysqL-0.1.7.3..
In file included from C.hsc:73:0:
include/MysqL_signals.h:9:19: Fatal error: MysqL.h: No such file or directory
#include "MysqL.h"
^
compilation terminated.
[...]
(所以实际上找到了库)
用于构建部分MysqL库的命令是这样的:(标记为更好的可读性)
/nix/store/6s3dl13ingr21z93dy6zxcc652wdlcrh-gcc-wrapper-6.4.0/bin/cc
-c
dist/build/Database/MysqL/Base/C_hsc_make.c
-o
dist/build/Database/MysqL/Base/C_hsc_make.o
-fno-stack-protector
-fno-stack-protector
-D__GLASGOW_HASKELL__=802
-Dlinux_BUILD_OS=1
-Dx86_64_BUILD_ARCH=1
-Dlinux_HOST_OS=1
-Dx86_64_HOST_ARCH=1
->>>>I/nix/store/6kl22pij3n5qppcmlg3a6m8ny19yylqj-mariadb-10.2.12//nix/store/6kl22pij3n5qppcmlg3a6m8ny19yylqj-mariadb-10.2.12/include/MysqL
->>>>I/nix/store/6kl22pij3n5qppcmlg3a6m8ny19yylqj-mariadb-10.2.12//nix/store/6kl22pij3n5qppcmlg3a6m8ny19yylqj-mariadb-10.2.12/include/MysqL/MysqL
-Iinclude
-Idist/build/autogen
-Idist/build/global-autogen
-include
dist/build/autogen/cabal_macros.h
-I/nix/store/75hyhwqmh2zh2wflffn1qgrrhy5nl8vg-ghc-8.2.2/lib/ghc-8.2.2/bytestring-0.10.8.2/include
-I/nix/store/75hyhwqmh2zh2wflffn1qgrrhy5nl8vg-ghc-8.2.2/lib/ghc-8.2.2/base-4.10.1.0/include
-I/nix/store/zi1rbssjvyyddjd4s8jmbardz11akd0s-gmp-6.1.2-dev/include
-I/nix/store/75hyhwqmh2zh2wflffn1qgrrhy5nl8vg-ghc-8.2.2/lib/ghc-8.2.2/integer-gmp-1.0.1.0/include
-I/nix/store/75hyhwqmh2zh2wflffn1qgrrhy5nl8vg-ghc-8.2.2/lib/ghc-8.2.2/include
-I/nix/store/75hyhwqmh2zh2wflffn1qgrrhy5nl8vg-ghc-8.2.2/lib/ghc-8.2.2/include/
假设它与链接和 nixos 的非 FHS 符合性有关,我将其添加到 .cabal
文件中的可执行文件中:
extra-lib-dirs: /nix/store/6kl22pij3n5qppcmlg3a6m8ny19yylqj-mariadb-10.2.1/include/server
extra-libraries: MysqL
构建结果没有变化。
这是我完整的 .cabal
文件:
cabal-version: 2.4
name: MysqLTest
version: 0.1.0.0
executable MysqLTest
main-is: Main.hs
build-depends: base >= 4.9 && < 4.13,MysqL ^>= 0.1.7
hs-source-dirs: app
default-language: Haskell2010
extra-lib-dirs: /nix/store/6kl22pij3n5qppcmlg3a6m8ny19yylqj-mariadb-10.2.1/include/server -- (from `which MysqL` in `nix-shell`)
extra-libraries: MysqL
我还尝试将库包含在 LIBRARY_PATH=[path/to/nix/store/MysqL/lib]:$LIBRARY_PATH cabal build --with-compiler ghc-8.2.2
(from here)
并将文件 MysqL.h
复制到 [cabal-project/libs]
并通过 extra-lib-dirs
和 extra-include-dirs
将其包含在 cabal 文件中;然而,也没有任何行为改变
我需要将 ghc-8.2.2
和 cabal
作为构建工具使用,因为这是一个更大的项目的一部分。
这是否需要对 nix-ld
进行一些调整(如果需要,如何调整?)还是有更简单的解决方案?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。