<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=GB2312" http-equiv=Content-Type>
<STYLE>
BLOCKQUOTE {
MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; MARGIN-LEFT: 2em
}
OL {
MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
UL {
MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
DIV.FoxDiv20130508102634651168 {
COLOR: #000000
}
P {
MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
BODY {
LINE-HEIGHT: 1.5; FONT-FAMILY: 微软雅黑; COLOR: #000080; FONT-SIZE: 10.5pt
}
</STYLE>
<META name=GENERATOR content="MSHTML 8.00.7600.17267"></HEAD>
<BODY style="MARGIN: 10px">
<DIV>hi, Dave</DIV>
<DIV> </DIV>
<DIV>and all friends reply my e-mail, I have figure out this problem.</DIV>
<DIV>My operating system is win7 64bits, so I use Visual Studio Tools
"Visual Studio X64 Command Line" in vs2010,</DIV>
<DIV>Run the same code, the same compile command, and it is works finally!</DIV>
<DIV> </DIV>
<DIV>I think the 64bits operating system is the key reason which cause this
error, but I really don't know why.</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>ckwei</DIV>
<DIV
style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0cm; PADDING-LEFT: 0cm; PADDING-RIGHT: 0cm; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt">
<DIV
style="PADDING-BOTTOM: 8px; PADDING-LEFT: 8px; PADDING-RIGHT: 8px; BACKGROUND: #efefef; COLOR: #000000; FONT-SIZE: 12px; PADDING-TOP: 8px">
<DIV><B>发件人:</B> <A href="mailto:dch@jsonified.com">Dave
Cottlehuber</A></DIV>
<DIV><B>发送时间:</B> 2013-05-07 21:31</DIV>
<DIV><B>收件人:</B> <A href="mailto:wckbluesky@yahoo.com.cn">wckbluesky</A>;
<A href="mailto:erlang-questions@erlang.org">erlang-questions</A></DIV>
<DIV><B>主题:</B> Re: Re: [erlang-questions] nif problem in
windows</DIV></DIV></DIV>
<DIV>
<DIV class=FoxDiv20130508102634651168>On 7 May 2013 15:15, 韦崇焜 <SPAN
dir=ltr><<A href="mailto:wckbluesky@yahoo.com.cn"
target=_blank>wckbluesky@yahoo.com.cn</A>></SPAN> wrote:<BR>
<DIV class=gmail_quote>
<BLOCKQUOTE
style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex"
class=gmail_quote><U></U>
<DIV style="MARGIN: 10px">
<DIV>hi, Dave,</DIV>
<DIV> </DIV>
<DIV>Thanks for you replying, I try your example and it is return the same
error I wrote before, here is the output:</DIV>
<DIV> </DIV>
<DIV>
<DIV>E:\firefox_download\hellonif-master>rebar.cmd compile</DIV>
<DIV>==> hellonif-master (compile)</DIV>
<DIV>Compiled src/hello.erl</DIV>
<DIV>
<DIV>Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86</DIV>
<DIV>Copyright (C) Microsoft Corporation. All rights reserved.</DIV>
<DIV> </DIV></DIV></DIV></DIV></BLOCKQUOTE>
<DIV><BR></DIV>
<DIV><BR></DIV>
<DIV>This is SDK 7.1 IIRC. That's good.</DIV>
<DIV> </DIV>
<BLOCKQUOTE
style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex"
class=gmail_quote>
<DIV style="MARGIN: 10px">
<DIV>
<DIV>
<DIV>hello.c</DIV>
<DIV>D:\Program Files (x86)\Microsoft Visual Studio 8\VC\INCLUDE\stdlib.h(215) : warn</DIV></DIV></DIV></DIV></BLOCKQUOTE>
<DIV><BR></DIV>
<DIV>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.</DIV>
<DIV><BR></DIV>
<BLOCKQUOTE
style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex"
class=gmail_quote>
<DIV style="MARGIN: 10px">
<DIV>
<DIV>
<DIV>ing C4255: '_get_purecall_handler' : no function prototype given: converting '()</DIV>
<DIV>' to '(void)'</DIV>
<DIV>d:\PROGRA~2\ERL510~1.1\erts-5.10.1\include\erl_nif.h(132) : warning C4820: '<unn</DIV></DIV></DIV></DIV></BLOCKQUOTE>
<DIV><BR></DIV>
<DIV>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. </DIV>
<BLOCKQUOTE
style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex"
class=gmail_quote>
<DIV style="MARGIN: 10px">
<DIV>
<DIV>
<DIV>amed-tag>' : '4' bytes padding added after data member 'ref_bin'</DIV>
<DIV>c_src/hello.c(3) : warning C4100: 'argv' : unreferenced formal parameter</DIV>
<DIV>c_src/hello.c(3) : warning C4100: 'argc' : unreferenced formal parameter</DIV>
<DIV>c_src/hello.c(13) : warning C4013: 'memcpy' undefined; assuming extern returning</DIV>
<DIV> int</DIV>
<DIV>Microsoft (R) Incremental Linker Version <A
href="tel:8.00.50727.42" target=_blank
value="+18005072742">8.00.50727.42</A></DIV>
<DIV>Copyright (C) Microsoft Corporation. All rights reserved.</DIV>
<DIV> </DIV></DIV></DIV></DIV></BLOCKQUOTE>
<DIV><BR></DIV>
<DIV>This linker doesn't match the SDK.</DIV>
<DIV> </DIV>
<BLOCKQUOTE
style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex"
class=gmail_quote>
<DIV style="MARGIN: 10px">
<DIV>
<DIV>
<DIV> 正在创建库 priv/hello.lib 和对象 priv/hello.exp</DIV></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>E:\firefox_download\hellonif-master>erl -pa ebin</DIV>
<DIV>Eshell V5.10.1 (abort with ^G)</DIV>
<DIV>1> hello:init().</DIV>
<DIV>{error,{load_failed,"Failed to load NIF library priv/hello: 'Unspecified error'"</DIV>
<DIV>}}</DIV>
<DIV>2> hello:world().</DIV>
<DIV>"NIF library not loaded"</DIV>
<DIV>3></DIV></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>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</DIV>
<DIV>I using operating system win7, is it matters?</DIV>
<DIV> </DIV>
<DIV></DIV></DIV></BLOCKQUOTE>
<DIV><BR></DIV>
<DIV>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? </DIV>
<DIV><BR></DIV>
<DIV>That should be enough to keep a clean compile using only the SDK
components, and skipping Visual C++ 8.</DIV>
<DIV><BR></DIV>
<BLOCKQUOTE
style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex"
class=gmail_quote>
<DIV style="MARGIN: 10px">
<DIV> </DIV>
<HR style="MIN-HEIGHT: 1px; WIDTH: 210px" align=left color=#b5c4df SIZE=1>
<DIV><SPAN>ckwei</SPAN></DIV>
<DIV> </DIV>
<DIV
style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0cm; PADDING-LEFT: 0cm; PADDING-RIGHT: 0cm; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt">
<DIV
style="PADDING-BOTTOM: 8px; PADDING-LEFT: 8px; PADDING-RIGHT: 8px; BACKGROUND: #efefef; FONT-SIZE: 12px; PADDING-TOP: 8px">
<DIV><B>From:</B> <A href="mailto:dch@jsonified.com" target=_blank>Dave
Cottlehuber</A></DIV>
<DIV><B>Date:</B> <A href="tel:2013-05-07%C2%A019" target=_blank
value="+12013050719">2013-05-07 19</A>:37</DIV>
<DIV><B>To:</B> <A href="mailto:erlang-questions@erlang.org"
target=_blank>erlang-questions</A></DIV>
<DIV><B>Subject:</B> Re: [erlang-questions] nif problem in
windows</DIV></DIV></DIV>
<DIV>
<DIV class=h5>
<DIV>
<DIV>
<DIV class=gmail_quote>
<DIV>
<DIV>On 7 May 2013 12:00, 韦崇焜 <SPAN dir=ltr><<A
href="mailto:wckbluesky@yahoo.com.cn"
target=_blank>wckbluesky@yahoo.com.cn</A>></SPAN> wrote:<BR></DIV></DIV>
<DIV class=gmail_quote>
<DIV>
<DIV>
<BLOCKQUOTE
style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex"
class=gmail_quote>hi<BR><BR>I am testing nif in windows right now, the nif c
code is very simple and it is copyed directly from <A
href="http://www.erlang.org/doc/tutorial/nif.html#id64988"
target=_blank>http://www.erlang.org/doc/tutorial/nif.html#id64988</A><BR><BR>All
the code is running well in Linux, and c code is compiled to .so in linux,
.dll in windows<BR><BR>Everything is ok before I running "c(complex6)" in
erlang VM, in windows,<BR><BR>it reports<BR><BR>=ERROR REPORT====
7-May-2013::17:36:19 ===<BR>Error in process <0.70.0> with exit value:
{{badmatch,{error,{load_failed,"Faile<BR>d to load NIF library
./complex6_nif: 'Unspecified
error'"}}},[{complex6,init,0,<BR>[{file,"complex6.erl"},{line,7}]},{code_server,'-handle_on_load/4-fun-0-',1,[{fi<BR>le,"code_server.erl"},...<BR><BR><BR>=ERROR
REPORT==== 7-May-2013::17:36:19 ===<BR>The on_load function for module
complex6 returned {{badmatch,<BR>
{error,<BR>
{load_failed,<BR>
"Failed to load NIF library ./complex6_nif:
'Unspecified error'"}}},<BR>
[{complex6,init,0,<BR>
[{file,...},{...}]},<BR>
{code_server,<BR>
'-handle_on_load/4-fun-0-',<BR>
1,<BR>
[{...}|...]}]}<BR>{error,on_load_failure}<BR><BR>It is hard to find
some useful information in google.<BR>Can anyone tell how to fix
it?<BR><BR></BLOCKQUOTE>
<DIV><BR></DIV></DIV></DIV>
<DIV>Hi ckwei,</DIV>
<DIV><BR></DIV>
<DIV>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.</DIV>
<DIV><BR></DIV>
<DIV><A href="https://github.com/vmx/hellonif"
target=_blank>https://github.com/vmx/hellonif</A></DIV>
<DIV><BR></DIV>
<DIV>A+</DIV><SPAN><FONT color=#888888>
<DIV>Dave</DIV>
<DIV> </DIV></FONT></SPAN></DIV><BR></DIV><BR></DIV></DIV></DIV></DIV></DIV></BLOCKQUOTE></DIV><BR></DIV></DIV></BODY></HTML>