logic.c
int addTwoIntegers(int a, int b)
{
return a + b;
}
test.nim
{.compile: "logic.c".}
proc addTwoIntegers(a, b: cint): cint {.importc.}
when isMainModule:
echo addTwoIntegers(3, 7)
E:\CODE\nim>nim -v
Nim Compiler Version 0.14.2 (2016-06-09) [Windows: amd64]
Copyright (c) 2006-2016 by Andreas Rumpf
git hash: 10fdd241ea1d987f12820b6c5467e21dc08d1c23
active boot switches: -d:release
when i run with nim c --cpu:i386 --passC:-m32 --passL:-m32 -r test.nim
E:\CODE\nim>nim c --cpu:i386 --passC:-m32 --passL:-m32 -r test.nim
Hint: used config file 'd:\Nim\config\nim.cfg' [Conf]
Hint: system [Processing]
Hint: test [Processing]
Hint: [Link]
Warning: resolving @addTwoIntegers@8 by linking to _addTwoIntegers
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
Hint: operation successful (10302 lines compiled; 0.297 sec total; 15.504MiB; De bug Build) [SuccessX]
1727172897
depends on your C compiler configuration, most of the times you need to specify the calling convention explicitly, for example: stdcall for msvc or cdecl for gcc
in your case, try add cdecl:
proc addTwoIntegers(a, b: cint): cint {.importc,cdecl.}