【发布时间】:2015-04-29 06:04:48
【问题描述】:
我写了一个 Nim 程序,
echo("Hello.")
然后我尝试为 Linux 机器进行交叉编译,
nim c --cpu:i386 --os:linux -c hello.nim
这产生了以下输出:
config/nim.cfg(45, 2) Hint: added path: '/Users/connor/.babel/pkgs/' [Path]
config/nim.cfg(46, 2) Hint: added path: '/Users/connor/.nimble/pkgs/' [Path]
Hint: used config file '/usr/local/lib/nim-0.10.2/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: hello [Processing]
Hint: operation successful (8753 lines compiled; 0.140 sec total; 14.148MB)[SuccessX]
此时我切换到nimcache/目录并尝试执行:
gcc hello.c -o hello.o
但这给了我一个错误:
hello.c:5:10: fatal error: 'nimbase.h' file not found
#include "nimbase.h"
^
1 error generated.
我想,“没什么大不了的,我会找到 nimbase.h 并将其放到那里的 nimcache 目录中”,但之后我又遇到了一个新错误,
In file included from hello.c:5:
./nimbase.h:385:28: error: 'assert_numbits' declared as an array with a
negative size
...sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof(NI)*8 ? 1 : -1];
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
我不确定我应该怎么做。我曾尝试使用--genScript 选项,但这导致了类似的错误。我正在运行 OS X Yosemite。
谢谢!
更新:
我不确定--cpu: 选项支持多少架构,但我在What makes Nim practical 博客文章中找到了(部分?)列表。我终于打电话了,
nim c --cpu:amd64 --os:linux -c hello.nim
这防止了我在我的 Linux 机器上编译时看到的错误。如果您使用的是 Linux 或 OS X,不确定您可以调用什么 CPU 架构,
less /proc/cpuinfo
【问题讨论】:
-
文档说“生成的 C 代码与平台无关。例如,为 Linux 生成的 C 代码不能在 Windows 上编译。”和“将 C 代码和编译脚本 compile_myproject.sh 移动到你的 Linux i386 机器”。所以也许你不能在 OS X 上完成这个。
-
哦,是的,我记得读过那个。我将
nimcache(与nimbase.h)scp'd 到我的linux 机器上,并再次收到最后一个错误。我还缺少什么吗?
标签: c compilation nim-lang