Visual c++ c_src\bcrypt_nif.c(94):错误C2275:&x27;ERL#u NIF#u术语';:非法使用此类型作为表达式

Visual c++ c_src\bcrypt_nif.c(94):错误C2275:&x27;ERL#u NIF#u术语';:非法使用此类型作为表达式,visual-c++,compiler-errors,erlang,elixir,bcrypt,Visual C++,Compiler Errors,Erlang,Elixir,Bcrypt,我想知道以前是否有人见过这个错误,如果是的话,该怎么办 C:\workspace\myproj>iex -S mix phx.server ==> bcrypt_elixir Microsoft (R) Program Maintenance Utility Version 10.00.30319.01 Copyright (C) Microsoft Corporation. All rights reserved. del /Q /F priv

我想知道以前是否有人见过这个错误,如果是的话,该怎么办

C:\workspace\myproj>iex -S mix phx.server
==> bcrypt_elixir

Microsoft (R) Program Maintenance Utility Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

        del /Q /F priv
        erl -eval "io:format(\"~s~n\", [lists:concat([\"ERTS_INCLUDE_PATH=\", code:root_dir(), \"/erts-\", erlang:system_info(version), \"/include\"])])" -s init stop -noshell > Makefile.auto.win
        nmake /                   /F Makefile.win priv\bcrypt_nif.dll

Microsoft (R) Program Maintenance Utility Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

        if NOT EXIST "priv" mkdir "priv"
        cl /O2 /EHsc /I"c_src /std:c11" /I"c:/Program Files/erl10.7/erts-10.7/include" /LD /MD /Fepriv\bcrypt_nif.dll  c_src\bcrypt_nif.c c_src\blowfish.c
Microsoft (R) C/C++ Optimizing Compiler Version 16.00.30319.01 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

bcrypt_nif.c
c_src\bcrypt_nif.c(94) : error C2275: 'ERL_NIF_TERM' : illegal use of this type as an expression
        c:/Program Files/erl10.7/erts-10.7/include\erl_nif.h(100) : see declaration of 'ERL_NIF_TERM'
c_src\bcrypt_nif.c(94) : error C2146: syntax error : missing ';' before identifier 'output'
c_src\bcrypt_nif.c(94) : error C2065: 'output' : undeclared identifier
c_src\bcrypt_nif.c(95) : error C2143: syntax error : missing ';' before 'type'
c_src\bcrypt_nif.c(97) : error C2065: 'output_data' : undeclared identifier
c_src\bcrypt_nif.c(99) : error C2065: 'output' : undeclared identifier
c_src\bcrypt_nif.c(377) : error C2143: syntax error : missing ';' before 'volatile'
c_src\bcrypt_nif.c(379) : error C2065: 'ptr' : undeclared identifier
c_src\bcrypt_nif.c(379) : error C2100: illegal indirection
c_src\bcrypt_nif.c(379) : error C2106: '=' : left operand must be l-value
blowfish.c
Generating Code...
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\cl.EXE"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\nmake.EXE"' : return code '0x2'
Stop.
could not compile dependency :bcrypt_elixir, "mix compile" failed. You can recompile this dependency with "mix deps.compile bcrypt_elixir", update it with "mix deps.update bcrypt_elixir" or clean it with "mix deps.clean bcrypt_elixir"
==> orcasite
** (Mix) Could not compile with "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\nmake.exe" (exit status: 2).
One option is to install a recent version of
[Visual C++ Build Tools](http://landinghub.visualstudio.com/visual-cpp-build-tools)
either manually or using [Chocolatey](https://chocolatey.org/) -
`choco install VisualCppBuildTools`.

After installing Visual C++ Build Tools, look in the "Program Files (x86)"
directory and search for "Microsoft Visual Studio". Note down the full path
of the folder with the highest version number. Open the "run" command and
type in the following command (make sure that the path and version number
are correct):

    cmd /K "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64

This should open up a command prompt with the necessary environment variables
set, and from which you will be able to run the "mix compile", "mix deps.compile",
and "mix test" commands.
我尝试在bcrypt Makefile.in中更改编译器的C版本,但结果是一样的

环境

操作系统:Windows10Pro

二郎:10.7

长生不老药:1.10.3

Microsoft C/C++优化编译器版本:适用于x64的16.00.30319.01


bcrypt_elixir:2.2.0

出于某种原因,C编译器最终无法理解遵循C99标准的代码;特别是,它不允许在函数的第一个语句之后声明变量

由于bcrypt_elixir有一个
Makefile.win
文件,这表明它以前在Windows上成功编译过,我不太明白为什么会发生这种情况,但无论如何,您应该能够通过修改
bcrypt_nif.c
来解决这一问题,更改如下:

static ERL_NIF_TERM bcrypt_gensalt_NIF(ErlNifEnv*env,int argc,const ERL_NIF_TERM argv[])
{
厄尔尼菲二元盐;
未签名整数对数_轮,小调;
if(argc!=3 | | |!enif|u inspect_二进制文件(env,argv[0],&csalt)||
csalt.size!=BCRYPT\u MAXSALT||
!enif_get_uint(环境、argv[1],&log_回合)||
!enif_get_uint(环境、argv[2]、和次要))
返回enif_make_badarg(环境);
ERL_NIF_术语输出;
unsigned char*output\u data=enif\u make\u new\u binary(env、BCRYPT\u SALTSPACE和output);
b crypt_initsalt(对数轮次,(uint8_t*)csalt.data,(char*)输出数据,(uint8_t)次);
返回输出;
}
为此:

static ERL_NIF_TERM bcrypt_gensalt_NIF(ErlNifEnv*env,int argc,const ERL_NIF_TERM argv[])
{
厄尔尼菲二元盐;
未签名整数对数_轮,小调;
/*增加了这两行*/
ERL_NIF_术语输出;
无符号字符*输出数据;
if(argc!=3 | | |!enif|u inspect_二进制文件(env,argv[0],&csalt)||
csalt.size!=BCRYPT\u MAXSALT||
!enif_get_uint(环境、argv[1],&log_回合)||
!enif_get_uint(环境、argv[2]、和次要))
返回enif_make_badarg(环境);
/*删除了一行,并修改了此行:*/
输出数据=enif生成新二进制文件(env、BCRYPT、SALT空间和输出);
b crypt_initsalt(对数轮次,(uint8_t*)csalt.data,(char*)输出数据,(uint8_t)次);
返回输出;
}

可能还有其他地方需要做类似的更改。

谢谢。是的,这个有效。将变量声明移到方法的顶部,并在整个文件中用_snprintf统一替换snprintf之后,错误消失了。