在c-compile期间使用luarocks为lua安装yaml的问题

时间:2016-08-17 15:28:19

标签: c windows lua yaml luarocks

我有lua,我使用了luarocks。

在Windows系统上

编辑

我通过从v202-3 from here下载luasocket-2.0.2-3.win32-x86.rock文件成功安装了luasocket。它是一个较旧的版本,但它的工作原理。

但是现在我需要安装yaml所以我可以使用yaml文件。现在我被迫使用* .src.rock文件或.rockspec文件进行安装。

我试过了:

luarocks install yaml给出:

D:\user\workspace\_lua>luarocks install yaml
Warning: Failed searching manifest: Failed fetching manifest for https://luarocks.org - Failed downloading https://luarocks.org/manifest - C:\Users\user\AppData\Local/LuaRocks/Cache/https___luarocks.org/manifest
Warning: Failed searching manifest: Failed fetching manifest for https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/ - Failed downloading https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/manifest - C:\Users\user\AppData\Local/LuaRocks/Cache/https___raw.githubusercontent.com_rocks-moonscript-org_moonrocks-mirror_master_/manifest
Warning: Failed searching manifest: Failed fetching manifest for http://luafr.org/moonrocks/ - Failed downloading http://luafr.org/moonrocks/manifest - C:\Users\user\AppData\Local/LuaRocks/Cache/http___luafr.org_moonrocks_/manifest
Warning: Failed searching manifest: Failed fetching manifest for http://luarocks.logiceditor.com/rocks - Failed downloading http://luarocks.logiceditor.com/rocks/manifest - C:\Users\user\AppData\Local/LuaRocks/Cache/http___luarocks.logiceditor.com_rocks/manifest

Error: No results matching query were found.

所以,然后我下载了yaml-1.1.2-1.src.rock并运行了命令: luarocks install yaml-1.1.2-1.src.rock

这告诉我,我有依赖yaml - > lub - > luafilesystem。所以我下载了:

  • luafilesystem-1.6.3-2.src.rock
  • LUB-1.1.0-1.src.rock
  • YAML-1.1.2-1.src.rock

我一个接一个地安装了它们,结果是:

  • luarocks install luafilesystem-1.6.3-2.src.rock - 确定
  • luarocks install lub-1.1.0-1.src.rock - 确定
  • luarocks install yaml-1.1.2-1.src.rock - FAILED,请参阅以下错误

错误日志:

D:\user\downloads\luarocks-2.3.0-win32\extras>luarocks install yaml-1.1.2-1.src.rock
Using yaml-1.1.2-1.src.rock... switching to 'build' mode
mingw32-gcc -O2 -c -o src/api.o -ID:/user/install/lua/luarocks/include src/api.c -Isrc
mingw32-gcc -O2 -c -o src/b64.o -ID:/user/install/lua/luarocks/include src/b64.c -Isrc
mingw32-gcc -O2 -c -o src/dumper.o -ID:/user/install/lua/luarocks/include src/dumper.c -Isrc
mingw32-gcc -O2 -c -o src/emitter.o -ID:/user/install/lua/luarocks/include src/emitter.c -Isrc
mingw32-gcc -O2 -c -o src/loader.o -ID:/user/install/lua/luarocks/include src/loader.c -Isrc
mingw32-gcc -O2 -c -o src/lyaml.o -ID:/user/install/lua/luarocks/include src/lyaml.c -Isrc
mingw32-gcc -O2 -c -o src/parser.o -ID:/user/install/lua/luarocks/include src/parser.c -Isrc
mingw32-gcc -O2 -c -o src/reader.o -ID:/user/install/lua/luarocks/include src/reader.c -Isrc
mingw32-gcc -O2 -c -o src/scanner.o -ID:/user/install/lua/luarocks/include src/scanner.c -Isrc
mingw32-gcc -O2 -c -o src/strtod.o -ID:/user/install/lua/luarocks/include src/strtod.c -Isrc
In file included from src/strtod.c:23:0:
src/strtod.c:24:17: warning: '_errno' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes]
 extern  int     errno;
                 ^
mingw32-gcc -O2 -c -o src/writer.o -ID:/user/install/lua/luarocks/include src/writer.c -Isrc
mingw32-gcc -shared -o yaml/core.dll src/api.o src/b64.o src/dumper.o src/emitter.o src/loader.o src/lyaml.o src/parser.o src/reader.o src/scanner.o src/strtod.o src/writer.o D:/user/install/lua/luarocks/lua5.1.lib -lMSVCR80
src/api.o:api.c:(.text+0x395): undefined reference to '_imp__yaml_realloc'
src/api.o:api.c:(.text+0x412): undefined reference to '_imp__yaml_string_extend'
            :
    LOTS OF THESE
            :
src/scanner.o:scanner.c:(.text.unlikely+0x29d0): undefined reference to '_imp__yaml_queue_extend'
src/scanner.o:scanner.c:(.text.unlikely+0x29e8): undefined reference to '_imp__yaml_token_delete'
collect2.exe: error: ld returned 1 exit status

Error: Build error: Failed compiling module yaml/core.dll

有谁知道为什么这个版本失败了? - 我直接从这里得到它:https://luarocks.org/modules/gaspard/yaml/1.1.2-1这是下载量最多的版本......所以我想它应该有用吗?

我的意思是,我可以看到错误是什么......但我不明白为什么会出现错误。我怎么解决这个问题?...任何帮助表示赞赏:)

更新

感谢siffiejoe的评论,我能够编译yaml摇滚乐。这是输出:

D:\user\downloads\luarocks-2.3.0-win32\extras>luarocks install yaml-1.1.2-1.src.rock CC="gcc -DYAML_DECLARE_STATIC"
Using yaml-1.1.2-1.src.rock... switching to 'build' mode
gcc -DYAML_DECLARE_STATIC -O2 -c -o src/api.o -ID:/user/install/lua/luarocks/include src/api.c -Isrc
gcc -DYAML_DECLARE_STATIC -O2 -c -o src/b64.o -ID:/user/install/lua/luarocks/include src/b64.c -Isrc
gcc -DYAML_DECLARE_STATIC -O2 -c -o src/dumper.o -ID:/user/install/lua/luarocks/include src/dumper.c -Isrc
gcc -DYAML_DECLARE_STATIC -O2 -c -o src/emitter.o -ID:/user/install/lua/luarocks/include src/emitter.c -Isrc
gcc -DYAML_DECLARE_STATIC -O2 -c -o src/loader.o -ID:/user/install/lua/luarocks/include src/loader.c -Isrc
gcc -DYAML_DECLARE_STATIC -O2 -c -o src/lyaml.o -ID:/user/install/lua/luarocks/include src/lyaml.c -Isrc
gcc -DYAML_DECLARE_STATIC -O2 -c -o src/parser.o -ID:/user/install/lua/luarocks/include src/parser.c -Isrc
gcc -DYAML_DECLARE_STATIC -O2 -c -o src/reader.o -ID:/user/install/lua/luarocks/include src/reader.c -Isrc
gcc -DYAML_DECLARE_STATIC -O2 -c -o src/scanner.o -ID:/user/install/lua/luarocks/include src/scanner.c -Isrc
gcc -DYAML_DECLARE_STATIC -O2 -c -o src/strtod.o -ID:/user/install/lua/luarocks/include src/strtod.c -Isrc
In file included from src/strtod.c:23:0:
src/strtod.c:24:17: warning: '_errno' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes]
 extern  int     errno;
                 ^
gcc -DYAML_DECLARE_STATIC -O2 -c -o src/writer.o -ID:/user/install/lua/luarocks/include src/writer.c -Isrc
mingw32-gcc -shared -o yaml/core.dll src/api.o src/b64.o src/dumper.o src/emitter.o src/loader.o src/lyaml.o src/parser.o src/reader.o src/scanner.o src/strtod.o src/writer.o D:/user/install/lua/luarocks/lua5.1.lib -lMSVCR80
Updating manifest for D:\user\install\lua\luarocks\systree/lib/luarocks/rocks
yaml 1.1.2-1 is now built and installed in D:\user\install\lua\luarocks\systree (license: MIT)

所以它说安装了。但是,当我尝试使用yaml packge时,它找不到它:

local yaml = require("yaml")
local data = yaml.load("mytest.yaml")

系统报告无法找到yaml.lua或yaml.dll。然后我在我发现的luarocks文件夹中搜索了* .lua和* .dll:

D:\user\install\lua\luarocks\systree>dir *.lua *.dll /b /s
D:\user\install\lua\luarocks\systree\lib\lua\5.1\lfs.dll
D:\user\install\lua\luarocks\systree\lib\lua\5.1\mime\core.dll
D:\user\install\lua\luarocks\systree\lib\lua\5.1\socket\core.dll
D:\user\install\lua\luarocks\systree\lib\lua\5.1\yaml\core.dll
D:\user\install\lua\luarocks\systree\lib\luarocks\rocks\luafilesystem\1.6.3-2\tests\test.lua
D:\user\install\lua\luarocks\systree\share\lua\5.1\ltn12.lua
D:\user\install\lua\luarocks\systree\share\lua\5.1\mime.lua
D:\user\install\lua\luarocks\systree\share\lua\5.1\socket.lua
D:\user\install\lua\luarocks\systree\share\lua\5.1\lub\Autoload.lua
D:\user\install\lua\luarocks\systree\share\lua\5.1\lub\Dir.lua
D:\user\install\lua\luarocks\systree\share\lua\5.1\lub\init.lua
D:\user\install\lua\luarocks\systree\share\lua\5.1\lub\Param.lua
D:\user\install\lua\luarocks\systree\share\lua\5.1\lub\Template.lua
D:\user\install\lua\luarocks\systree\share\lua\5.1\socket\ftp.lua
D:\user\install\lua\luarocks\systree\share\lua\5.1\socket\http.lua
D:\user\install\lua\luarocks\systree\share\lua\5.1\socket\smtp.lua
D:\user\install\lua\luarocks\systree\share\lua\5.1\socket\tp.lua
D:\user\install\lua\luarocks\systree\share\lua\5.1\socket\url.lua
D:\user\install\lua\luarocks\systree\share\lua\5.1\yaml\init.lua

例如,我设法用luarocks install luasocket-2.0.2-3.win32-x86.rock安装luasocket,因为有一个.rock文件可用。所以你可以看到有一个socket.lua。对于yaml,lub和luafilesystem,我可以看到各种安装位置,但是没有.lua或.dll文件...... 我特意搜索了yaml:

D:\user\install\lua\luarocks\systree>dir *yaml* /b /s
D:\user\install\lua\luarocks\systree\lib\lua\5.1\yaml
D:\user\install\lua\luarocks\systree\lib\luarocks\rocks\yaml
D:\user\install\lua\luarocks\systree\lib\luarocks\rocks\yaml\1.1.2-1\yaml-1.1.2-1.rockspec
D:\user\install\lua\luarocks\systree\share\lua\5.1\yaml

嗯......所以我去git克隆了这个项目(必须下载zip文件,因为我的愚蠢的IT阻止了我的git clone ...(端口443)。

所以终于把它排序了,然后在我试过的yaml-master文件夹中:

luarocks make yaml-1.1.2-1.rockspec CC-"gcc -DYAML_DECLARE_STATIC"

这与以前的效果相同。所以现在我尝试了.src.rock和.rockspec类型......

我再次陷入困境:(

更新2

当我从git构建时,顶层有一个名为yaml.lua的文件。但它包含的只是文本yaml/init.lua ...不知道该怎么做 - 尝试将其复制到我的..install\lua\luarocks\systree\share\lua\5.1目录中,但是当我运行我的测试lua projam时它会出错... ..发生了什么,它很难安装:(

更新3

继siffiejoe的回答之后,我或多或少地安装了这个yaml。但我有一个错误运行它:

这是我的lua脚本:

package.path = "D:\\user\\install\\lua\\luarocks\\systree\\share\\lua\\5.1\\?\\init.lua;" .. package.path
print("package.path: " .. package.path)
local yaml = require("yaml")
local data = yaml.load("mytest.yaml")

我在测试时手动添加lua路径。当我运行这个时,我得到了窗口:

enter image description here

我的日志看起来像:

D:\user\install\lua\luarocks\systree\share\lua\5.1\?\init.lua;D:\user\install\lua\luarocks\systree\share\lua\5.1\?.lua;D:\user\install\lua\luarocks\systree\share\lua\5.1\?\init.lua;./?.lua;./?/init.lua;./lua/?.lua;./lua/?/init.lua;D:\user\install\lua\zerobrane\lualibs/?/?.lua;D:\user\install\lua\zerobrane\lualibs/?.lua;D:\user\install\lua\zerobrane\lualibs/?/?/init.lua;D:\user\install\lua\zerobrane\lualibs/?/init.lua
D:\user\install\lua\zerobrane\bin\lua.exe: error loading module 'lfs' from file 'D:\user\install\lua\luarocks\systree\lib\lua\5.1\lfs.dll':
    The specified procedure could not be found.


stack traceback:
    [C]: at 0x66df0460
    [C]: in function 'require'
    ...\install\lua\luarocks\systree\share\lua\5.1\lub\init.lua:17: in main chunk
    [C]: in function 'require'
    ...install\lua\luarocks\systree\share\lua\5.1\yaml\init.lua:25: in main chunk
    [C]: in function 'require'
    D:\user\workspace\_lua\myluatest.lua:3: in main chunk
    [C]: at 0x00402a57
Program completed in 56.64 seconds (pid: 15856).

所以它似乎回到了这个MSVCR80.dll ......这对我没有意义,我认为这与微软有关...我读过的一些事情可能是一个损坏的MSVCR80.dll需要更换或某事。但我还不确定为什么会这样。有什么想法吗?

1 个答案:

答案 0 :(得分:3)

src/yaml.h中的包含文件github repository包含以下预处理器代码:

Remainder #>0, Remainder #= P rem Q.

这意味着在Windows上,默认情况下所有与yaml相关的函数都用#ifdef WIN32 # if defined(YAML_DECLARE_STATIC) # define YAML_DECLARE(type) type # elif defined(YAML_DECLARE_EXPORT) # define YAML_DECLARE(type) __declspec(dllexport) type # else # define YAML_DECLARE(type) __declspec(dllimport) type # endif #else # define YAML_DECLARE(type) type #endif 进行修饰(链接器错误消息中的__declspec(dllimport)前缀是提示)。因此,链接器期望这些函数位于外部DLL中。但是yaml代码被捆绑并与Lua绑定到一个DLL _imp__一起编译,因此链接器会抱怨。解决此问题的正确方法是从yaml函数中删除所有与导入/导出相关的装饰,这可以通过定义yaml\core.dll来实现。这个宏应该在rockspec中设置(我稍后会发布一个bug报告),但是一个快速而肮脏的解决方案是通过命令行上的YAML_DECLARE_STATIC变量设置它:

CC

之后,LuaRocks目录中的某处应该有一个luarocks install yaml-1.1.2-1.src.rock CC="mingw32-gcc -DYAML_DECLARE_STATIC" 文件和一个yaml\core.dll文件。要使用Lua yaml绑定,您必须确保yaml\init.lua加载require("yaml")文件,yaml\init.lua加载require("yaml.core")。这可以通过添加到yaml\core.dll / package.path(来自您的Lua脚本)或最好添加到package.cpath / LUA_PATH来实现。由于已安装的LuaSocket已经可以正常工作,因此您可能正常设置LUA_CPATH / LUA_PATH,但yaml绑定使用不同的方法来加载其主Lua模块而不是LuaSocket:LuaSocket有LUA_CPATH对于socket.lua,但yaml require("socket")yaml\init.lua。这种方法的优点是任何Lua子模块(例如require("yaml"))都与主Lua模块的代码位于同一目录中。无论如何,你还必须添加

yaml.a

到您的D:\user\install\lua\luarocks\systree\share\lua\5.1\?\init.lua 环境变量。

顺便说一下,你在github存储库中找到的LUA_PATH文件是一个符号链接,无论如何都无法在Windows上正常工作(但它可能会干扰,所以你不应该把它放到你的岩石树中) 。这只是为了方便开发。