[英]Issues installing yaml for lua with luarocks during the c-compile
I have lua, that I isntalled using luarocks. 我有lua,我喜欢用luackcks迷恋。
Edit: on a windows system 编辑:在Windows系统上
I successfully installed luasocket by downloading the luasocket-2.0.2-3.win32-x86.rock file from v202-3 from here . 我从这里从v202-3下载luasocket-2.0.2-3.win32-x86.rock文件,成功安装了luasocket。 Its an older version, but it works.
它是一个较旧的版本,但是可以工作。
However now I need to install yaml so I can work with yaml files. 但是,现在我需要安装yaml,以便可以使用yaml文件。 Now I am forced to install using a *.src.rock file or a .rockspec file.
现在,我被迫使用* .src.rock文件或.rockspec文件进行安装。
I have tried: 我努力了:
luarocks install yaml
which gives: 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.
So, then I downloaded yaml-1.1.2-1.src.rock
and ran the command: luarocks install yaml-1.1.2-1.src.rock
因此,然后我下载了
yaml-1.1.2-1.src.rock
并运行了命令: luarocks install yaml-1.1.2-1.src.rock
This told me that I had dependencies yaml --> lub --> luafilesystem. 这告诉我,我有依赖性yaml-> lub-> luafilesystem。 so then I downloaded:
所以我下载了:
And I installed them one after the other with the result: 我将它们一个接一个地安装,结果是:
luarocks install luafilesystem-1.6.3-2.src.rock
- OK luarocks install luafilesystem-1.6.3-2.src.rock
确定 luarocks install lub-1.1.0-1.src.rock
- OK luarocks install lub-1.1.0-1.src.rock
确定 luarocks install yaml-1.1.2-1.src.rock
- FAILED, see errors below luarocks install yaml-1.1.2-1.src.rock
失败,请参见以下错误 Error log: 错误日志:
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
Does anyone know why this build fails? 有谁知道为什么这个构建失败? - I got it directly from here:
https://luarocks.org/modules/gaspard/yaml/1.1.2-1
which is the most downloaded version... so I guess it should work? -我是直接从这里获得的:
https://luarocks.org/modules/gaspard/yaml/1.1.2-1
: https://luarocks.org/modules/gaspard/yaml/1.1.2-1
,这是下载次数最多的版本...所以我认为它应该可以工作吗?
I mean, I can see what the error is... but I don't understand why there should be an error. 我的意思是,我可以看到错误是什么...但是我不明白为什么会有错误。 How can I resolve this?... Any help appreciated :)
我该如何解决呢?
UPDATE UPDATE
Thanks to siffiejoe's comment, I was able to compile the yaml rock. 感谢siffiejoe的评论,我得以编译yaml岩石。 Here is the output:
这是输出:
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)
So it says it is installed. 因此它说它已安装。 However when I try to use the yaml packge it does not find it:
但是,当我尝试使用yaml packge时,找不到它:
local yaml = require("yaml")
local data = yaml.load("mytest.yaml")
The system reports that it can't find yaml.lua or yaml.dll. 系统报告找不到yaml.lua或yaml.dll。 I then searched *.lua and *.dll in my luarocks folder I found:
然后,我在发现的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
For example, I managed to install luasocket with luarocks install luasocket-2.0.2-3.win32-x86.rock
because there was a .rock file available. 例如,我设法通过
luarocks install luasocket-2.0.2-3.win32-x86.rock
来安装luasocket,因为存在一个.rock文件。 And so you can see there is a socket.lua. 这样您就可以看到有一个socket.lua。 For yaml, lub and luafilesystem I can see various install locations, but there is no .lua or .dll files... I searched more for yaml specifically:
对于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
ehh... so then I went and cloned the project from git (had to download the zip file because my stupid IT blocked my git clone ... (port 443). 嗯...所以后来我从git克隆了项目(必须下载zip文件,因为我的愚蠢的IT阻止了我的git克隆...(端口443)。
So finally got that sorted, then in the yaml-master folder I tried: 所以最终得到了排序,然后在yaml-master文件夹中尝试了:
luarocks make yaml-1.1.2-1.rockspec CC-"gcc -DYAML_DECLARE_STATIC"
This had the same effect as before. 效果与以前相同。 So now I have tried both .src.rock and .rockspec types...
所以现在我已经尝试了.src.rock和.rockspec类型...
I am stuck again :( 我又被卡住了:(
UPDATE 2 更新2
When I built from git, there was a file called yaml.lua in the top level. 当我从git构建时,顶层有一个名为yaml.lua的文件。 But all it contains is the text
yaml/init.lua
... not sure what to do with that - tried copying it into the my ..install\\lua\\luarocks\\systree\\share\\lua\\5.1
dir, but when I run my test lua projam it gives an error.... what is going on, it can't be this hard to install :( 但是它包含的只是文本
yaml/init.lua
...不确定该怎么做-尝试将其复制到我的..install\\lua\\luarocks\\systree\\share\\lua\\5.1
目录中,但是当我运行时我的测试lua projam它给出了一个错误....怎么回事,安装起来不是那么困难:(
UPDATE 3 更新3
Following on from siffiejoe's great answer, I have more or less got this yaml installed. 继siffiejoe的一个很好的答案之后,我或多或少安装了这个yaml。 But I have a bug running it:
但是我有一个运行它的错误:
Here is my lua script: 这是我的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")
I am manually adding the lua path for now while I am testing. 我正在测试时,现在手动添加lua路径。 When I run this I get the window:
当我运行它时,我得到一个窗口:
And my log looks like: 我的日志如下所示:
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).
So it appears to come back to this MSVCR80.dll ... this is not making sense to me, I assume this is do with microsoft... Some things I have read about it could be a corrupt MSVCR80.dll that needs replacing or somthing. 因此,它似乎又回到了此MSVCR80.dll ...对我而言这没有意义,我认为这与Microsoft有关...我已了解到的一些信息可能是损坏的MSVCR80.dll,需要替换或东西 But I am not yet sure about why this is occuring.
但是我不确定为什么会这样。 Any thoughts?
有什么想法吗?
The include file src/yaml.h
from the github repository contains the following preprocessor code: github存储库中的包含文件
src/yaml.h
包含以下预处理程序代码:
#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
That means that on Windows all yaml-related functions by default are decorated with __declspec(dllimport)
(the _imp__
prefixes in the linker error messages were hints). 这意味着在Windows上,默认情况下,所有与yaml相关的功能均以
__declspec(dllimport)
装饰__declspec(dllimport)
链接器错误消息中的_imp__
前缀为提示)。 Because of this the linker expects those functions to be in an external DLL. 因此,链接器希望这些功能在外部DLL中。 But the yaml code is bundled and compiled together with the Lua binding into a single DLL
yaml\\core.dll
, and so the linker complains. 但是yaml代码是与Lua捆绑在一起打包和编译在一起的,成为一个DLL
yaml\\core.dll
,因此链接器会抱怨。 The correct way to fix this is to remove all import/export-related decorations from the yaml functions, and this can be achieved by defining YAML_DECLARE_STATIC
. 解决此问题的正确方法是从yaml函数中删除所有与导入/导出相关的装饰,这可以通过定义
YAML_DECLARE_STATIC
来实现。 This macro should definitely be set in the rockspec (I'll post a bug report later), but a quick and dirty solution is to set it via the CC
variable on the commandline: 绝对应该在rockspec中设置该宏(我将在稍后发布错误报告),但是一种快速而肮脏的解决方案是通过命令行上的
CC
变量对其进行设置:
luarocks install yaml-1.1.2-1.src.rock CC="mingw32-gcc -DYAML_DECLARE_STATIC"
After that there should be a yaml\\core.dll
file and a yaml\\init.lua
file somewhere in your LuaRocks directory. 之后,在您的LuaRocks目录中的某个位置应该有一个
yaml\\core.dll
文件和一个yaml\\init.lua
文件。 To use the Lua yaml binding you have to make sure that a require("yaml")
loads the yaml\\init.lua
file, and that require("yaml.core")
loads yaml\\core.dll
. 要使用Lua yaml绑定,必须确保
require("yaml")
加载yaml\\init.lua
文件,并且require("yaml.core")
加载yaml\\core.dll
。 This can be achieved by adding to package.path
/ package.cpath
(from within your Lua script) or preferably by adding to LUA_PATH
/ LUA_CPATH
. 这可以通过添加到
package.path
/ package.cpath
(在Lua脚本中)或最好通过添加到LUA_PATH
/ LUA_CPATH
。 Since the installed LuaSocket already works, you probably have LUA_PATH
/ LUA_CPATH
mostly set up correctly, but the yaml binding uses a different approach for loading its main Lua module than LuaSocket: LuaSocket has socket.lua
for require("socket")
, but yaml has yaml\\init.lua
for require("yaml")
. 由于已安装的LuaSocket已经可以使用,因此您可能已经正确设置了
LUA_PATH
/ LUA_CPATH
,但是yaml绑定使用的加载主Lua模块的方式与LuaSocket的加载方法不同:LuaSocket具有用于require("socket")
socket.lua
,但是yaml具有yaml\\init.lua
作为require("yaml")
。 This approach has the advantage that any Lua submodules (eg yaml.a
) would be in the same directory as the code for the main Lua module. 这种方法的优势在于,任何Lua子模块(例如
yaml.a
)都将与主Lua模块的代码位于同一目录中。 Anyway, you also have to add 无论如何,您还必须添加
D:\user\install\lua\luarocks\systree\share\lua\5.1\?\init.lua
to your LUA_PATH
environment variable. 到您的
LUA_PATH
环境变量。
Btw., the yaml.lua
file you found in the github repository is a symbolic link and won't work correctly on Windows anyway (but it could interfere, so you shouldn't put it into your rocks tree). 顺便说一句,您在github存储库中找到的
yaml.lua
文件是一个符号链接,无论如何在Windows上都无法正常工作(但它可能会干扰,因此您不应将其放入您的岩石树中)。 It's only there for convenience during development. 它只是为了开发过程中的方便。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.