Hi, Stefan.
Thank you for providing me the links, which indeed solved the problem. Below, I
will describe the solution, in case someone else comes across the same problem.
1 -- I wanted to compile dynamic Internet pages running on a Linux server. My
machine is a Macintosh mini box. I used homebrew to install the
x86_64-linux-musl-gcc
2 -- Here is my nim.cfg:
amd64.linux.gcc.path:"/usr/local/Cellar/musl-cross/0.9.8/bin"
amd64.linux.gcc.exe:"x86_64-linux-musl-gcc"
amd64.linux.gcc.linkerexe:"x86_64-linux-musl-gcc"
Run
3 -- Here is the build.nims that I use to compile the Internet page:
#!/usr/bin/env -S nim --hints:off
mode = ScriptMode.Silent
if paramCount() > 1 and fileExists(paramStr(3) & ".nim"):
let
app = paramStr(3)
src = app & ".nim"
exe = "nim" & app & ".x "
c = "nim c --nimcache:xx --os:linux --cpu:amd64 -d:danger -o:"
cc= " --passL:\"-static\""
exec c & exe & " " & cc & " " & src
echo c & exe & " " & cc & " " & src
else: echo "Usage: ./build.nims <app without extension>"
Run
4 -- Here is the program I want to compile:
# File: recfib.nim
import os, strutils
proc fib(n: int): int =
if n<2: result= n+1
elif n<3: result= fib(n-1)+fib(n-2)
else: result= fib(n-3)+fib(n-2)+fib(n-2)
echo fib(paramStr(1).parseInt)
Run
5 -- Here is the compilation:
~/nim/os› ./build.nims recfib
Run
6 -- I send the code to my son's Internet server:
~/nim/os› scp -P2222 nimrecfib.x [email protected]:~/
Run
7 -- I enter the server in the cloud and test the program:
~/nim/os› ssh -p2222 [email protected]
[email protected] [~]# time ./nimrecfib.x 40
267914296
real 0m0.011s
user 0m0.000s
sys 0m0.010s
Run