[erlang-questions] 回复: Re: nif problem in windows

=?gb2312?B?zqSz559q?= wckbluesky@REDACTED
Wed May 8 04:31:16 CEST 2013


hi, Dave

and all friends reply my e-mail, I have figure out this problem.
My operating system is win7 64bits, so I use Visual Studio Tools "Visual Studio X64 Command Line" in vs2010,
Run the same code, the same compile command, and it is works finally!

I think the 64bits operating system is the key reason which cause this error, but I really don't know why.


ckwei
·¢¼þÈË£º Dave Cottlehuber
·¢ËÍʱ¼ä£º 2013-05-07 21:31
ÊÕ¼þÈË£º wckbluesky; erlang-questions
Ö÷Ì⣺ Re: Re: [erlang-questions] nif problem in windows
On 7 May 2013 15:15, Τ³çŸj <wckbluesky@REDACTED> wrote:

hi, Dave,

Thanks for you replying, I try your example and it is return the same error I wrote before, here is the output:

E:\firefox_download\hellonif-master>rebar.cmd compile
==> hellonif-master (compile)
Compiled src/hello.erl
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.





This is SDK 7.1 IIRC. That's good.

hello.c
D:\Program Files (x86)\Microsoft Visual Studio 8\VC\INCLUDE\stdlib.h(215) : warn


I think you have an SDK that doesn't match the header files you're providing it here. No idea if that is supposed to work, but it smells bad to me.


ing C4255: '_get_purecall_handler' : no function prototype given: converting '()
' to '(void)'
d:\PROGRA~2\ERL510~1.1\erts-5.10.1\include\erl_nif.h(132) : warning C4820: '<unn


The above NIF was done with R14 only at the time. I'm pretty sure R15 also works fine, as we use this same approach in CouchDB today, but I've not tested it in R16B yet. 
amed-tag>' : '4' bytes padding added after data member 'ref_bin'
c_src/hello.c(3) : warning C4100: 'argv' : unreferenced formal parameter
c_src/hello.c(3) : warning C4100: 'argc' : unreferenced formal parameter
c_src/hello.c(13) : warning C4013: 'memcpy' undefined; assuming extern returning
 int
Microsoft (R) Incremental Linker Version 8.00.50727.42
Copyright (C) Microsoft Corporation.  All rights reserved.



This linker doesn't match the SDK.

   ÕýÔÚ´´½¨¿â priv/hello.lib ºÍ¶ÔÏó priv/hello.exp


E:\firefox_download\hellonif-master>erl -pa ebin
Eshell V5.10.1  (abort with ^G)
1> hello:init().
{error,{load_failed,"Failed to load NIF library priv/hello: 'Unspecified error'"
}}
2> hello:world().
"NIF library not loaded"
3>


Notice that, I change the code hello.erl slightly, it catch all the error when erlang:load_nif, I delete it, so it can output the error message
I using operating system win7, is it matters?



OS shouldn't matter, no. But the mismatch of compiler + linker + header files likely does matter. Can you try this with a clean environment (path set to minimum windows specific ones, and libs, include variables set to empty) and then run setsdk.cmd /x86 /release before adding erlang headers and path? 


That should be enough to keep a clean compile using only the SDK components, and skipping Visual C++ 8.






ckwei

From: Dave Cottlehuber
Date: 2013-05-07 19:37
To: erlang-questions
Subject: Re: [erlang-questions] nif problem in windows
On 7 May 2013 12:00, Τ³çŸj <wckbluesky@REDACTED> wrote:

hi

I am testing nif in windows right now, the nif c code is very simple and it is copyed directly from http://www.erlang.org/doc/tutorial/nif.html#id64988

All the code is running well in Linux, and c code is compiled to .so in linux, .dll in windows

Everything is ok before I running "c(complex6)" in erlang VM, in windows,

it reports

=ERROR REPORT==== 7-May-2013::17:36:19 ===
Error in process <0.70.0> with exit value: {{badmatch,{error,{load_failed,"Faile
d to load NIF library ./complex6_nif: 'Unspecified error'"}}},[{complex6,init,0,
[{file,"complex6.erl"},{line,7}]},{code_server,'-handle_on_load/4-fun-0-',1,[{fi
le,"code_server.erl"},...


=ERROR REPORT==== 7-May-2013::17:36:19 ===
The on_load function for module complex6 returned {{badmatch,
                                                    {error,
                                                     {load_failed,
                                                      "Failed to load NIF library ./complex6_nif: 'Unspecified error'"}}},
                                                   [{complex6,init,0,
                                                     [{file,...},{...}]},
                                                    {code_server,
                                                     '-handle_on_load/4-fun-0-',
                                                     1,
                                                     [{...}|...]}]}
{error,on_load_failure}

It is hard to find some useful information in google.
Can anyone tell how to fix it?




Hi ckwei,


It might be useful to paste some of the source code that isn't working for you. I don't have windows handy, but here's a NIF example that works on both Windows using command shell and SDK 7.1,  and LInux, that Volker & I did last year. The erlang side NIF loader was poached from one of Paul Davis' projects IIRC.


https://github.com/vmx/hellonif


A+
Dave
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130508/4eaa4fe8/attachment.htm>


More information about the erlang-questions mailing list