mysql - 无法在 NixOS 上构建 haskell 包 mysql
问题描述
我正在尝试使用 构建最基本的 haskell 项目cabal-3.2.0.0
,ghc-8.2.2
该项目使用mysql-0.1.7.3
.
我使用cabal init
添加mysql ^>= 0.1.7
到.cabal
文件中来设置项目。然后我还添加了这个shell.nix
文件以将库依赖项纳入范围:
所以我添加了一个shell.nix
文件来明确地将所有内容纳入范围:(这是从这里派生的)
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
(从这里)
并通过cabal 文件将文件复制mysql.h
到[cabal-project/libs]
并包含在其中;但是,行为也没有任何改变extra-lib-dirs
extra-include-dirs
因为这是一个更大的项目的一部分,所以我需要使用它ghc-8.2.2
并cabal
作为构建工具。这是否需要一些调整nix-ld
(如果需要如何调整?)还是有更简单的解决方案?
解决方案
推荐阅读
- javascript - 如何将 HTML 文本输入设置为始终保留 2 位小数
- java - 布尔变量不应该改变
- android - 动态多个微调器“setOnItemSelectedListener()”在项目点击时不起作用 - Android
- media-source - mediasouce中什么mimeCodec兼容ie和火狐
- java - 从 Angular 10 中的 jar 运行小程序
- python - Python urllib3 AWS 弹性搜索连接错误
- python - 在遍历字符串中单词的每个字母后创建句子
- node.js - 在firebase云功能中为nodemailer创建自定义电子邮件模板?
- r - 如何在使用 rvest 在 R 中抓取时跳过空白页面?
- apache-kafka - RHEL 8 操作系统与 Apache Kafka 2.5.0 的兼容性