Nim入信への道~改宗に洗礼は付きものなのである~

アバター
MoNoQLoREATOR
記事: 284
登録日時: 14年前
住所: 東京

Nim入信への道~改宗に洗礼は付きものなのである~

投稿記事 by MoNoQLoREATOR » 10年前

前回の日記への返信ありがとうございます。
しかし今はWindowsでやっておりまして、Macの作業に戻るのは明日か明後日になります。

さて、とりあえずWindows側でやってみました。

まず、Nim公式のIDEは使い物になりません。文字が見えません。バグでしょう。

次に、Nim公式には

CODE:

Note: The Nim compiler requires a C compiler to compile software. On Windows we recommend that you use Mingw-w64. GCC is recommended on Linux and Clang on Mac.
と書かれていますが、どうやらWindowsではMingw-w64というソフトウェアを使ってGCCをインストールするのがおすすめだという意味のようです。
私は最初
Windows:Mingw-w64コンパイラ
Linux:GCCコンパイラ
Mac:Clangコンパイラ
が推奨されているという意味なのかと思っていました。

また、gcc.exeへのパスは自分で通す必要があります。

私は今までVisualStudioぐらいしか使ったことが無かったので、このあたりのことが全くわからず路頭に迷っていました。

さて、これで環境は整ったはずなので、最も単純だと思われるNimプログラムをコンパイルしてみます。

test.nim
[codeNim]echo "Hello, Nim!"[/code]

CODE:

C:\Users\MoNoQLoREATOR\Documents\projects\nim\first_test>nim c -r test.nim
c:\nim\config\nim.cfg(53, 3) Hint: added path: 'C:\Users\MoNoQLoREATOR\.babel\pkgs\' [Path]
c:\nim\config\nim.cfg(54, 3) Hint: added path: 'C:\Users\MoNoQLoREATOR\.nimble\pkgs\' [Path]
Hint: used config file 'C:\Nim\config\nim.cfg' [Conf]
Hint: system [Processing]
Hint: test [Processing]
CC: test
CC: stdlib_system
In file included from c:\users\monoqloreator\documents\projects\nim\first_test\nimcache\test.c:8:0:
C:\Nim\lib/nimbase.h:393:13: error: size of array 'assert_numbits' is negative
 typedef int assert_numbits[sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof(NI)*8 ? 1 : -1];
             ^
In file included from c:\users\monoqloreator\documents\projects\nim\first_test\nimcache\stdlib_system.c:8:0:
C:\Nim\lib/nimbase.h:393:13: error: size of array 'assert_numbits' is negative
 typedef int assert_numbits[sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof(NI)*8 ? 1 : -1];
             ^
Error:  execution of an external program failed; rerun with --parallelBuild:1 to see the error message
はい、残念でした。
まあ、コンパイル自体が可能な段階まで進んだので、今日のところはこれでよしとしましょう。
おやすみなさい。


アバター
みけCAT
記事: 6734
登録日時: 14年前

Re: Nim入信への道~改宗に洗礼は付きものなのである~

投稿記事 by みけCAT » 10年前

32bit版のNim (今32bit版を使っているなら64bit版のNim) を使いましょう
http://nim-lang.org/download.html

アバター
MoNoQLoREATOR
記事: 284
登録日時: 14年前
住所: 東京

Re: Nim入信への道~改宗に洗礼は付きものなのである~

投稿記事 by MoNoQLoREATOR » 10年前

ありがとうございます。
ということは、32bitとしてコンパイルすれば通るのではないか?と思いやってみました

CODE:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\MoNoQLoREATOR>cd documents/projects/nim/first_test

C:\Users\MoNoQLoREATOR\Documents\projects\nim\first_test>nim c -r --cpu:i386 --os:windows test.nim
c:\nim\config\nim.cfg(53, 3) Hint: added path: 'C:\Users\MoNoQLoREATOR\.babel\pkgs\' [Path]
c:\nim\config\nim.cfg(54, 3) Hint: added path: 'C:\Users\MoNoQLoREATOR\.nimble\pkgs\' [Path]
Hint: used config file 'C:\Nim\config\nim.cfg' [Conf]
Hint: system [Processing]
Hint: test [Processing]
CC: test
CC: stdlib_system
[Linking]
Hint: operation successful (9227 lines compiled; 11.692 sec total; 14.143MB; Debug Build) [SuccessX]
c:\users\monoqloreator\documents\projects\nim\first_test\test.exe
Hello, Nim!

C:\Users\MoNoQLoREATOR\Documents\projects\nim\first_test>
いよっしゃぁぁぁぁぁあああああああああああああ!!

とりあえずコンパイル自体はできるってことがわかりました。嬉しい。

64bit向けにもコンパイルしたいので、64bit版gccをインストールしてきます。

アバター
MoNoQLoREATOR
記事: 284
登録日時: 14年前
住所: 東京

Re: Nim入信への道~改宗に洗礼は付きものなのである~

投稿記事 by MoNoQLoREATOR » 10年前

MinGWのBasicSetupだと、インストールの項目にmingw32-gccと表示されていて明らかに32bit版っぽいので、とりあえず MSYS System Builder のmsys-gccというものをインストールしてみることにしました。64bitなのかどうかはわからないです。でも少なくとも32とは書いてないので。。。

やってみました

CODE:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\MoNoQLoREATOR>cd documents

C:\Users\MoNoQLoREATOR\Documents>cd projects/nim/first_test

C:\Users\MoNoQLoREATOR\Documents\projects\nim\first_test>nim c test.nim
c:\nim\config\nim.cfg(53, 3) Hint: added path: 'C:\Users\MoNoQLoREATOR\.babel\pkgs\' [Path]
c:\nim\config\nim.cfg(54, 3) Hint: added path: 'C:\Users\MoNoQLoREATOR\.nimble\pkgs\' [Path]
Hint: used config file 'C:\Nim\config\nim.cfg' [Conf]
Hint: system [Processing]
Hint: test [Processing]
CC: test
CC: stdlib_system
In file included from c:\users\monoqloreator\documents\projects\nim\first_test\nimcache\stdlib_system.c:8:In file included from c:\users\monoqloreator\documents\projects\nim\first_test\nimcache\test.c:8:
C:/Nim/lib/nimbase.h:393: error: size of array `assert_numbits' is negative

Error:  execution of an external program failed; rerun with --parallelBuild:1 to see the error message

C:\Users\MoNoQLoREATOR\Documents\projects\nim\first_test>nim c --parallelBuild:1 test.nim
c:\nim\config\nim.cfg(53, 3) Hint: added path: 'C:\Users\MoNoQLoREATOR\.babel\pkgs\' [Path]
c:\nim\config\nim.cfg(54, 3) Hint: added path: 'C:\Users\MoNoQLoREATOR\.nimble\pkgs\' [Path]
Hint: used config file 'C:\Nim\config\nim.cfg' [Conf]
Hint: system [Processing]
Hint: test [Processing]
gcc.exe -c  -w  -IC:\Nim\lib -o c:\users\monoqloreator\documents\projects\nim\first_test\nimcache\test.o c:\users\monoqloreator\documents\projects\nim\first_test\nimcache\test.c
In file included from c:\users\monoqloreator\documents\projects\nim\first_test\nimcache\test.c:8:
C:/Nim/lib/nimbase.h:393: error: size of array `assert_numbits' is negative
Error: execution of an external program failed

C:\Users\MoNoQLoREATOR\Documents\projects\nim\first_test>
前回とはエラーの内容が若干違いますね。
正直わけわかめです。
とりあえずこれより優先順位が高いタスクがあるのでそっちを先に片づけて来ます。

ISLe
記事: 2650
登録日時: 14年前

Re: Nim入信への道~改宗に洗礼は付きものなのである~

投稿記事 by ISLe » 10年前

>64bit版
コンパイラが64bit版なのかターゲットが64bitなのか区別しないとハマりそうですが。
MinGW(32)とMinGW64の違いは(コンパイラの)実行形式なので、どちらを使っても、ターゲットを32bit/64bitいずれもコンパイルできます。

アバター
みけCAT
記事: 6734
登録日時: 14年前

Re: Nim入信への道~改宗に洗礼は付きものなのである~

投稿記事 by みけCAT » 10年前

コンパイラが対応しているなら、gccでは-m32 / -m64オプションで32bit / 64bitを切り替えられます。
Nimの--passC:OPTIONオプションでC言語のコンパイラにオプションを渡せます。(リンカには--passL:OPTION)