According to [Nim Backend 
Integration,](https://nim-lang.org/docs/backends.html#interfacing-backend-code-calling-nim)
 I have the following code 
    
    
    type Vec3t {.exportc.} = object
      x, y, z: float32
    
    proc test_add(x, y, z: float32): Vec3t {.exportc.} =
      Vec3t(x: x, y: y, z: z)
    
    proc print_point_nim(p: Vec3t) {.exportc.} =
      echo "[Nim] p.x: ", p.x
    
    
    Run

compiled with 
    
    
    nim c -d:release -d:danger --gc:refc --noMain --noLinking --nimcache:ncache 
--header:TEST.H TEST.NIM
    
    
    Run

However, when called in C there are linker errors like 
    
    
    /usr/bin/ld: /tmp/ccXiaS2r.o: in function `main':
    LIGHT.C:(.text+0x148): undefined reference to `NimMain()'
    LIGHT.C:(.text.startup+0x52): undefined reference to `test_add(float, 
float, float)'
    /usr/bin/ld: light: hidden symbol `_Z8test_addfff' isn't defined
    /usr/bin/ld: final link failed: bad value
    collect2: error: ld returned 1 exit status
    
    
    Run

Tried with `nim cpp` instead with `nim c` and it compiles, but whenever the 
function is called it drops segfault.

It works on test project, but if I can't integrate it into existing C 
application.

Are there any specific compiler switches to overcome this?

Also, why even with the `--header` flag Nim still produces object files?

Shouldn't it compile only the .c sources, and then compile them in the next 
stage with gcc?

Reply via email to