问题描述
我想从nim代码创建一个dll。但是我没有注册一些其他导出比NimMainInner。
即使我尝试这个简单的例子,它不工作:
proc Hellow():cint {.exportc。} =
echo(hello)
返回1
它与 nim c --app:lib libh4x.nim
和 nim c -d:release --app:lib --no_main libh4x.nim
我使用 Nim Compiler版本0.11.2(2015-05-04)[Windows:i386 ]
检查dll我使用 dllexp.exe
。
我也试图加载dll与python ctypes,但我的导出都没有显示或可调用。我可以看到在结果dll中的proc名称与hexeditor。
我错过了什么?
拼写错误。所以我更改了定义:
proc Hellow():cint {.exportc,dynlib。} =
echo (你好)
结果= 1
b
$ b
注意:如果您使用pythons ctypes和函数参数,请使用 ctypes.cdll.LoadLibrary
而不是 ctypes.windll.LoadLibrary
:
并声明这样的功能:
proc myinit(procid:int){.cdecl,exportc,dynlib。} =
discard
I want to create a dll from nim code.But i failed to register some other exports than "NimMainInner".Even if i try this simple example its not working:
proc Hellow(): cint {.exportc.} =
echo("hello")
return 1
i've compiled it with nim c --app:lib libh4x.nim
and nim c -d:release --app:lib --no_main libh4x.nim
i use Nim Compiler Version 0.11.2 (2015-05-04) [Windows: i386]
to inspect the dll i use dllexp.exe
.I've also tried to load the dll with python ctypes, but none of my exports are shown or are callable. I can see the proc name in the resulting dll with an hexeditor, though.
What have i missed here?
The dynlib pragma was missing. So i changed the definition to:
proc Hellow(): cint {.exportc,dynlib.} =
echo("hello")
result = 1
now it works.
Note: If you use this with pythons ctypes and with function parameters make shure to use ctypes.cdll.LoadLibrary
instead of ctypes.windll.LoadLibrary
:Python ctypes argument errors
and to declare the function like this:
proc myinit(procid : int) {.cdecl,exportc,dynlib.} =
discard
这篇关于如何正确创建一个nim / nimrod windows dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!