Can someone help me out, i am trying to cross-compile to
rpi4 alpine-musl ( 5.4.43-0-rpi4 #1-Alpine SMP PREEMPT Thu May 28 10:01:20 UTC 2020 aarch64 Linux )
form normal pc ( 5.8.8_1 #1 SMP Wed Sep 9 19:53:06 UTC 2020 x86_64 GNU/Linux - voidlinux :) )
So simple code i am using just for testing:
import ws, asyncdispatch, asynchttpserver
var server = newAsyncHttpServer()
proc cb(req: Request) {.async.} =
try:
if req.url.path == "/ws":
var ws = await newWebSocket(req)
await ws.send("Welcome to simple echo server")
while ws.readyState == Open:
let packet = await ws.receiveStrPacket()
await ws.send(packet)
elif req.url.path == "/":
await req.respond(Http200, "Heloo")
else:
await req.respond(Http404, "5min ban for bots!")
except:
return
waitFor server.serve(Port(9010), cb)
What i think(duno for sure anymore) i tryed but did not work:
nim c --cpu:arm64 --passL:"-static -no-pie" src/server.nim
./serv: line 1: syntax error: unexpected word (expecting ")")
nim --cpu:arm64 --gcc.exe:musl-gcc --gcc.linkerexe:musl-gcc c server.nim #not even puting -d:ssl
./serv: line 2: syntax error: unexpected ")"
nim --cpu:arm64 --os:linux --gcc.exe:musl-gcc --gcc.linkerexe:musl-gcc c server.nim #tryed adding -os:linux
./serv: line 2: syntax error: unexpected ")"
nim --cpu:arm64 --gcc.exe:musl-gcc --gcc.linkerexe:musl-gcc --passL:-static c -d:ssl src/server.nim
./serv: line 1: ELF: not found
./serv: line 2: syntax error: unexpected ")"
nim --cpu:arm64 --gcc.exe:musl-gcc --gcc.linkerexe:musl-gcc c -d:ssl src/server.nim
./serv: line 1: l: not found
./serv: line 1: ELF: not found
./serv: line 12: syntax error: unterminated quoted string
#tryed https://github.com/kaushalmodi/hello_musl
nim musl --cpu:arm64 src/hello_musl.nim
./serv: line 1: syntax error: unexpected word (expecting ")")
Gcc i think i have everything needed
[*] cross-aarch64-linux-gnu-0.33_3 GNU Cross toolchain for the aarch64-linux-gnu LE target (binutils/gcc/g...
[*] cross-aarch64-linux-gnu-libc-0.33_3 GNU Cross toolchain for the aarch64-linux-gnu LE target (binutils/gcc/g...
[*] cross-aarch64-linux-musl-0.33_3 Cross toolchain for ARM64 LE target (musl)
[*] cross-aarch64-linux-musl-libc-0.33_3 Cross toolchain for ARM64 LE target (musl) - libc files
[*] cross-x86_64-linux-musl-0.33_4 Cross toolchain for x86_64 with musl
[*] cross-x86_64-linux-musl-libc-0.33_4 Cross toolchain for x86_64 with musl - libc files
[*] gcc-9.3.0_6 GNU Compiler Collection
[*] libgcc-9.3.0_6 GNU Compiler Collection - GCC library
[*] libgcc-devel-9.3.0_6 GNU Compiler Collection - GCC library - development files
./serv was just that build of /src/server.nim , atm dumped that am just building file.nim that hase just 1 line echo "HelloW"
From what i get i get those errors ")" cuz wrong arch or wrong libc ?
But why is the OS trying to run the binary at all? The nim commands shown didn't include -r. And the output of server.nim wouldn't be named serv.
Also, why would the OS try to run a binary as a shellscript? It shouldn't do that unless it starts with something like #! /bin/bash...
he's compiled on his laptop, then i'm assuming scp'd them across to the rpi to ~/.serv then run that file over ssh. ...lots of assumptions on my part i admit
the error messages certainly look like something is parsing ./serv and the fact it sometimes finds "ELF" on line 1 indicates it's probably a binary. i googled it and it's not unheard of
"if the executable runs on your local machine, if so it hasn't cross compiled properly."
ye i just runed nim --cpu:arm64 --gcc.exe:musl-gcc --gcc.linkerexe:musl-gcc c echotest.nim file echotest.nim has just echo "Test1" and it runned on my x86_64amdPC like it ignored this --cpu:arm64, duno why ?
im --cpu:arm64 --gcc.exe:musl-gcc --gcc.linkerexe:musl-gcc c echotest.nim
Hint: used config file '/home/me/.choosenim/toolchains/nim-1.2.6/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: echotest [Processing]
CC: stdlib_io.nim
CC: stdlib_system.nim
CC: echotest.nim
Hint: [Link]
Hint: 14204 LOC; 0.490 sec; 16.023MiB peakmem; Debug build; proj: /home/me/Documents/Projects/TestDelete3/echotest.nim; out: /home/me/Documents/Projects/TestDelete3/echotest [SuccessX]
[me@oldcan TestDelete3]$ ls
echotest echotest.nim
< got no error while bulding Yes, Nim can't find your cross-gcc. Have you got the right``arm.linux.gcc.path`` and the rest in your nim.cfg?
After that, I had to passL the path to the libc as well
ye i put -ld but now i get new errors nim.cfg
arm64.linux.gcc.exe = "aarch64-linux-musl-gcc"
arm64.linux.gcc.linkerexe = "aarch64-linux-musl-ld"
nim c -f --cpu:arm64 echotest.nim
Hint: used config file '/home/me/.choosenim/toolchains/nim-1.2.6/config/nim.cfg' [Conf]
Hint: used config file '/home/me/Documents/Projects/TestDelete3/nim.cfg' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: echotest [Processing]
CC: stdlib_io.nim
CC: stdlib_system.nim
CC: echotest.nim
Hint: [Link]
aarch64-linux-musl-ld: warning: cannot find entry symbol _start; defaulting to 0000000000400120
aarch64-linux-musl-ld: /home/me/.cache/nim/echotest_d/stdlib_io.nim.c.o: in function `echoBinSafe':
stdlib_io.nim.c:(.text+0x244): undefined reference to `stdout'
aarch64-linux-musl-ld: stdlib_io.nim.c:(.text+0x248): undefined reference to `stdout'
aarch64-linux-musl-ld: stdlib_io.nim.c:(.text+0x250): undefined reference to `flockfile'
aarch64-linux-musl-ld: stdlib_io.nim.c:(.text+0x328): undefined reference to `stdout'
aarch64-linux-musl-ld: stdlib_io.nim.c:(.text+0x32c): undefined reference to `stdout'
aarch64-linux-musl-ld: stdlib_io.nim.c:(.text+0x340): undefined reference to `fwrite'
aarch64-linux-musl-ld: stdlib_io.nim.c:(.text+0x3a8): undefined reference to `stdout'
aarch64-linux-musl-ld: stdlib_io.nim.c:(.text+0x3ac): undefined reference to `stdout'
aarch64-linux-musl-ld: stdlib_io.nim.c:(.text+0x3c8): undefined reference to `fwrite'
aarch64-linux-musl-ld: stdlib_io.nim.c:(.text+0x3e8): undefined reference to `stdout'
aarch64-linux-musl-ld: stdlib_io.nim.c:(.text+0x3ec): undefined reference to `stdout'
aarch64-linux-musl-ld: stdlib_io.nim.c:(.text+0x3f4): undefined reference to `fflush'
aarch64-linux-musl-ld: stdlib_io.nim.c:(.text+0x410): undefined reference to `stdout'
aarch64-linux-musl-ld: stdlib_io.nim.c:(.text+0x414): undefined reference to `stdout'
aarch64-linux-musl-ld: stdlib_io.nim.c:(.text+0x41c): undefined reference to `funlockfile'
aarch64-linux-musl-ld: /home/me/.cache/nim/echotest_d/stdlib_system.nim.c.o: in function `nimCopyMem':
stdlib_system.nim.c:(.text+0x28): undefined reference to `memcpy'
aarch64-linux-musl-ld: /home/me/.cache/nim/echotest_d/stdlib_system.nim.c.o: in function `nimCStrLen':
stdlib_system.nim.c:(.text+0x1a70): undefined reference to `strlen'
aarch64-linux-musl-ld: /home/me/.cache/nim/echotest_d/stdlib_system.nim.c.o: in function `rawWrite':
stdlib_system.nim.c:(.text+0x1acc): undefined reference to `fwrite'
aarch64-linux-musl-ld: stdlib_system.nim.c:(.text+0x1adc): undefined reference to `fflush'
aarch64-linux-musl-ld: /home/me/.cache/nim/echotest_d/stdlib_system.nim.c.o: in function `raiseOutOfMem__mMRdr4sgmnykA9aWeM9aDZlw_2':
stdlib_system.nim.c:(.text+0x1b74): undefined reference to `stderr'
aarch64-linux-musl-ld: stdlib_system.nim.c:(.text+0x1b78): undefined reference to `stderr'
aarch64-linux-musl-ld: stdlib_system.nim.c:(.text+0x1ba8): undefined reference to `exit'
aarch64-linux-musl-ld: /home/me/.cache/nim/echotest_d/stdlib_system.nim.c.o: in function `osAllocPages__HMOhWrY1QMa49a2BcJwSDZQsystem':
stdlib_system.nim.c:(.text+0x1c3c): undefined reference to `mmap'
aarch64-linux-musl-ld: /home/me/.cache/nim/echotest_d/stdlib_system.nim.c.o: in function `osTryAllocPages__HMOhWrY1QMa49a2BcJwSDZQ_2system':
stdlib_system.nim.c:(.text+0x1d64): undefined reference to `mmap'
aarch64-linux-musl-ld: /home/me/.cache/nim/echotest_d/stdlib_system.nim.c.o: in function `nimSetMem__zxfKBYntu9cBapkhrCOk1fgmemory':
stdlib_system.nim.c:(.text+0x1e44): undefined reference to `memset'
aarch64-linux-musl-ld: /home/me/.cache/nim/echotest_d/stdlib_system.nim.c.o: in function `osDeallocPages__dRMEutPSAkbR9b9blNmTzvoQsystem':
stdlib_system.nim.c:(.text+0x58ec): undefined reference to `munmap'
aarch64-linux-musl-ld: /home/me/.cache/nim/echotest_d/stdlib_system.nim.c.o: in function `markStackAndRegisters__U6T7JWtDLrWhtmhXSoy9a6g':
stdlib_system.nim.c:(.text+0x6144): undefined reference to `setjmp'
aarch64-linux-musl-ld: /home/me/.cache/nim/echotest_d/stdlib_system.nim.c.o: in function `raiseExceptionAux__na8C8pUZ9cLQWVwk35l5vfw':
stdlib_system.nim.c:(.text+0xbdc0): undefined reference to `longjmp'
aarch64-linux-musl-ld: stdlib_system.nim.c:(.text+0xbdd4): undefined reference to `exit'
aarch64-linux-musl-ld: /home/me/.cache/nim/echotest_d/stdlib_system.nim.c.o: in function `writeToStdErr__a2kDfqdSc1eYf0ZCWOGinQ':
stdlib_system.nim.c:(.text+0xc158): undefined reference to `stderr'
aarch64-linux-musl-ld: stdlib_system.nim.c:(.text+0xc15c): undefined reference to `stderr'
aarch64-linux-musl-ld: /home/me/.cache/nim/echotest_d/stdlib_system.nim.c.o: in function `showErrorMessage__zsORN9crdKxsL9cHrQcdHSMw':
stdlib_system.nim.c:(.text+0xc1b8): undefined reference to `setjmp'
aarch64-linux-musl-ld: /home/me/.cache/nim/echotest_d/stdlib_system.nim.c.o: in function `callDepthLimitReached__mMRdr4sgmnykA9aWeM9aDZlw':
stdlib_system.nim.c:(.text+0xc308): undefined reference to `exit'
aarch64-linux-musl-ld: /home/me/.cache/nim/echotest_d/stdlib_system.nim.c.o: in function `nimRegisterThreadLocalMarker':
stdlib_system.nim.c:(.text+0xc920): undefined reference to `stderr'
aarch64-linux-musl-ld: stdlib_system.nim.c:(.text+0xc924): undefined reference to `stderr'
aarch64-linux-musl-ld: stdlib_system.nim.c:(.text+0xc954): undefined reference to `exit'
aarch64-linux-musl-ld: /home/me/.cache/nim/echotest_d/stdlib_system.nim.c.o: in function `signalHandler':
stdlib_system.nim.c:(.text+0xcc94): undefined reference to `exit'
aarch64-linux-musl-ld: /home/me/.cache/nim/echotest_d/stdlib_system.nim.c.o: in function `registerSignalHandler__amVlU9ajqZ06ujoesRBHcDg_3':
stdlib_system.nim.c:(.text+0xccb0): undefined reference to `signal'
aarch64-linux-musl-ld: stdlib_system.nim.c:(.text+0xccc8): undefined reference to `signal'
aarch64-linux-musl-ld: stdlib_system.nim.c:(.text+0xcce0): undefined reference to `signal'
aarch64-linux-musl-ld: stdlib_system.nim.c:(.text+0xccf8): undefined reference to `signal'
aarch64-linux-musl-ld: stdlib_system.nim.c:(.text+0xcd10): undefined reference to `signal'
aarch64-linux-musl-ld: /home/me/.cache/nim/echotest_d/stdlib_system.nim.c.o:stdlib_system.nim.c:(.text+0xcd28): more undefined references to `signal' follow
Error: execution of an external program failed: 'aarch64-linux-musl-ld -o /home/me/Documents/Projects/TestDelete3/echotest /home/me/.cache/nim/echotest_d/stdlib_io.nim.c.o /home/me/.cache/nim/echotest_d/stdlib_system.nim.c.o /home/me/.cache/nim/echotest_d/@mechotest.nim.c.o -ldl'
Nice!!!
I'm doing it a little differently because I think using the musl C library means you need to compile statically, but I needed to depend on a dynamic library. So I installed a fairly old GCC (via the arch linux aur repository, other linux distros have other options). This means I have a binary that I can compile dynamically but will be compatible with most boxes.
arm64.linux.gcc.exe = "aarch64-none-linux-gnu-gcc-9.2.1" arm64.linux.gcc.linkerexe = "aarch64-none-linux-gnu-gcc-9.2.1"