【问题标题】:How to use Nix to build software that uses time.h on macOS如何使用 Nix 在 macOS 上构建使用 time.h 的软件
【发布时间】:2019-03-06 04:01:14
【问题描述】:

我有一些用 C 编写的软件。它编译得很好,但是当我尝试将其打包为 Nix 包时,编译器会发出错误

未知类型名称'clockid_t';你是说'clock_t'吗?

这是一个 MCVE:

default.nix:

with import <nixpkgs> {};
stdenv.mkDerivation {
  name = "asdf";
  src = lib.cleanSource ./.;
}

main.c:

#include <stdio.h>
#include <time.h>

clockid_t x;

int main() { return 0; }

制作文件:

all:
    cc main.c -o main

将这些文件放在一个目录中并执行nix-build 会产生以下输出:

these derivations will be built:
  /nix/store/8djs648bj3bqrn0bz51hmf79wdifks2b-asdf.drv
building '/nix/store/8djs648bj3bqrn0bz51hmf79wdifks2b-asdf.drv'...
unpacking sources
unpacking source archive /nix/store/zm8c46i44hp2gr9gc7n41f3vg02jh2v5-asdf
source root is asdf
patching sources
configuring
no configure script, doing nothing
building
build flags: SHELL=/nix/store/g9cis4hsnzcjkzfa77nif7kzq9bsqmpg-bash-4.4-p23/bin/bash
cc main.c -o main
main.c:4:1: error: unknown type name 'clockid_t'; did you mean 'clock_t'?
clockid_t x;
^~~~~~~~~
clock_t
/nix/store/l77bg1s15f0wgjf4c12fc29ghvjbswwy-Libsystem-osx-10.11.6/include/sys/_types/_clock_t.h:30:33: note: 'clock_t' declared here
typedef __darwin_clock_t        clock_t;
                                ^
1 error generated.
make: *** [makefile:2: all] Error 1
builder for '/nix/store/8djs648bj3bqrn0bz51hmf79wdifks2b-asdf.drv' failed with exit code 2
error: build of '/nix/store/8djs648bj3bqrn0bz51hmf79wdifks2b-asdf.drv' failed

但是当我简单地运行make 时没有错误。我该如何解决这个问题?

【问题讨论】:

    标签: c macos nix


    【解决方案1】:

    这似乎是自 10.11.6 以来您在派生中使用的 OS X 中已修复的编译错误。

    升级到更新的 nixpkgs 应该可以解决这个问题。 Nixpkgs 18.09 应该足够了。

    【讨论】:

    • 我使用的是 OS X 10.13 和 nixpkgs 19.09。
    猜你喜欢
    • 2017-03-22
    • 1970-01-01
    • 2021-12-20
    • 1970-01-01
    • 2020-05-25
    • 1970-01-01
    • 2018-03-09
    • 2018-05-09
    • 2021-10-01
    相关资源
    最近更新 更多