Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
This example fails to compile, saying undefined reference to `CPU_ZERO'
Example
import std/os
var t: Thread[void]
proc test =
while true:
echo "in thread!"
sleep(1000)
proc main =
createThread(t, test)
pinToCpu(t, 2)
while true:
sleep(1000)
main()
Current Output
Compiler logs
davide@arch /t/tests> nim c -r --threads:on test.nim
Hint: used config file '/home/davide/.choosenim/toolchains/nim-1.4.8/config/nim.cfg' [Conf]
Hint: used config file '/home/davide/.choosenim/toolchains/nim-1.4.8/config/config.nims' [Conf]
..................CC: stdlib_assertions.nim
CC: stdlib_locks.nim
CC: stdlib_sharedlist.nim
CC: stdlib_io.nim
CC: stdlib_system.nim
CC: stdlib_times.nim
CC: stdlib_os.nim
CC: test.nim
Hint: [Link]
/usr/bin/ld: /home/davide/.cache/nim/test_d/stdlib_system.nim.c.o: in function `pinToCpu__cOvMVoT2TGICB4WVS7s5BA':
stdlib_system.nim.c:(.text+0xf817): undefined reference to `CPU_ZERO'
/usr/bin/ld: stdlib_system.nim.c:(.text+0xf836): undefined reference to `CPU_SET'
collect2: error: ld returned 1 exit status
Error: execution of an external program failed: 'gcc -o /tmp/tests/test /home/davide/.cache/nim/test_d/stdlib_assertions.nim.c.o /home/davide/.cache/nim/test_d/stdlib_locks.nim.c.o /home/davide/.cache/nim/test_d/stdlib_sharedlist.nim.c.o /home/davide/.cache/nim/test_d/stdlib_io.nim.c.o /home/davide/.cache/nim/test_d/stdlib_system.nim.c.o /home/davide/.cache/nim/test_d/stdlib_times.nim.c.o /home/davide/.cache/nim/test_d/stdlib_os.nim.c.o /home/davide/.cache/nim/test_d/@mtest.nim.c.o -pthread -lm -lrt -ldl'
It works fine on Nim 1.6.0, however it doesn't compile on 1.4.8.
Tested on Arch Linux:
Linux arch 5.14.12-arch1-1 #1 SMP PREEMPT Wed, 13 Oct 2021 16:58:16 +0000 x86_64 GNU/Linux
I installed Nim using choosenim.
$ nim -v
Nim Compiler Version 1.4.8 [Linux: amd64]
Compiled at 2021-05-25
Copyright (c) 2006-2021 by Andreas Rumpf
git hash: 44e653a9314e1b8503f0fa4a8a34c3380b26fff3
active boot switches: -d:release
$ choosenim show
Selected: 1.6.0
Channel: stable
Path: /home/davide/.choosenim/toolchains/nim-1.6.0
Versions:
* 1.6.0
1.4.8
0.15.2
This example fails to compile, saying
undefined reference to `CPU_ZERO'
Example
Current Output
Compiler logs
Expected Output
Program should compile.
Possible Solution
nim c -r --threads:on --passC:-D_GNU_SOURCE test.nim
works correctly (https://stackoverflow.com/questions/24034631/error-message-undefined-reference-for-cpu-zero/24034698)Additional Information
It works fine on Nim 1.6.0, however it doesn't compile on 1.4.8. Tested on Arch Linux:
Linux arch 5.14.12-arch1-1 #1 SMP PREEMPT Wed, 13 Oct 2021 16:58:16 +0000 x86_64 GNU/Linux
I installed Nim using choosenim.