I am tryin to port some C code to Nim, but I need to meet a particular API. To do so I am using externc. But when I compile the code it looks like it is not finding what I am looking for.
I have something like this:
type
fmi2Boolean* {.exportc:"$1".} = cint
I compile the whole code like this:
$ nim c --nimcache:.cache --app:lib -o:inc.so inc.nim
I am getting the following error:
/home/jose/src/fmi.nim/src/.cache/@minc.nim.c:48:9: error: nombre de tipo ‘fmi2Boolean’ desconocido
48 | typedef fmi2Boolean tyArray__9a3P2QfHP8jQP9aHIjVmK8Hg[4];
> Meaning: error name of type fmi2Boolean unknown.
Any clue about what am I doing wrong?
Here's a minimal working example:
##foo.nim
type
Foo*{.exportc.} = cint
##bar.nim
import foo
proc bar*(f: var Foo){.exportc.} =
#anything here, just so bar gets emitted
f = 3
related to https://github.com/nim-lang/Nim/issues/11797 i think
I am getting this:
$ nim c --nimcache:.cache --app:lib -o:inc.so bar.nim
Hint: used config file '/home/jose/.choosenim/toolchains/nim-1.4.2/config/nim.cfg' [Conf]
Hint: used config file '/home/jose/.choosenim/toolchains/nim-1.4.2/config/config.nims' [Conf]
.....CC: stdlib_system.nim
CC: bar.nim
/tmp/.cache/@mbar.nim.c:39:36: error: nombre de tipo ‘Foo’ desconocido
39 | N_LIB_PRIVATE N_NIMCALL(void, bar)(Foo* f);
| ^~~
/tmp/.cache/@mbar.nim.c:80:36: error: nombre de tipo ‘Foo’ desconocido
80 | N_LIB_PRIVATE N_NIMCALL(void, bar)(Foo* f) {
| ^~~
Error: execution of an external compiler program 'gcc -c -w -fmax-errors=3 -fPIC -I/home/jose/.choosenim/toolchains/nim-1.4.2/lib -I/tmp -o /tmp/.cache/@mbar.nim.c.o /tmp/.cache/@mbar.nim.c' failed with exit code: 1
Lesson/workaround: Don't {.exportc.} ctypes. your options:
##fmi2TypesPlatform.nim
type
#fmi2Boolean*{.exportc:"$1".} = cint #no
fmi2Boolean* = cint #fine results in "int"
fmi2Boolean* = int32 #fine results in "NI32"
fmi2Boolean*{.exportc:"$1".} = int32 #fine, results in "NI32"
Well I fixed the issues by replacing cint with int32, cdouble with float64 and cuint with uint32.
Thanks a lot for your help.