我有一些用C语言编写的软件,它编译得很好,但是当我试图将它打包成Nix包时,编译器会发出错误
未知的类型名“clockid”是指“clock”吗?
这是一个MCVE:
默认.nix:
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "asdf";
src = lib.cleanSource ./.;
}
主要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
时没有错误。我该怎么解决? 最佳答案
这似乎是一个编译错误,在OSX中从10.11.6开始就被修复了,您在派生中使用它。
升级到新的nixpkgs应该可以解决这个问题。尼克斯帕克斯18.09应该足够了。
关于c - 如何在Mac OS上使用Nix来构建使用time.h的软件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55015358/