How do I get the c code of a nim program?
Asked Answered
K

3

20

I followed the docs and compiled with nim compileToC helloworld.nim but it just spit out an executable. How can I see the intermediate C representation?

Kamat answered 30/4, 2015 at 0:21 Comment(0)
C
17

2019 Update (Nim 0.19.2)

The default nimcache directory has changed from the current working directory to:

  • $HOME/.cache/nim/<project_name> for Linux and MacOS
  • $HOME/nimcache/<project_name> for Windows

See the relevant nim compiler documentation article for details.

Coronation answered 1/2, 2019 at 4:26 Comment(0)
D
16

nim -c -d:release c helloworld.nim just creates the C files in nimcache, without compiling and linking them. -d:release makes the code easier to read.

Dogberry answered 30/4, 2015 at 8:27 Comment(1)
and nimcache location depends on OS, on my system the C files ended up under ~/.cache/nim/, in a directory named after each nim source file, with suffix _d or _r, presumably for "debug" and "release". You can control this with --nimcache:... command line switch.Octans
K
3

Solved: When you compile a nim program a nimcache directory is automatically generated in the same directory that contains the c code.

Kamat answered 30/4, 2015 at 2:35 Comment(1)
Not for a while, it seems. Nothing is generated in the working directory in 0.19.Boykins

© 2022 - 2024 — McMap. All rights reserved.