简体   繁体   English

lua 5.2中缺少print.c,试图从源代码进行构建

[英]print.c is missing from lua 5.2, trying to build from source

I am trying to build Lua from source and when I look at http://www.lua.org/source/5.2/ I basically see what I got in the source file, and I don't see print.c . 我正在尝试从源代码构建Lua,当我查看http://www.lua.org/source/5.2/时 ,基本上可以看到源文件中包含的内容,而看不到print.c

In my build.bat (I am doing this on Windows 7) I have this: 在我的build.bat中(我正在Windows 7上执行此操作),我有以下内容:

cl /MD /O2 /W3 /c /DLUA_BUILD_AS_DLL *.c
del *.o
ren lua.obj lua.o
ren luac.obj luac.o
ren print.obj print.o
link /DLL /IMPLIB:lua5.2.lib /OUT:lua5.2.dll *.obj
link /OUT:lua.exe lua.o lua5.2.lib
lib /out:lua5.2-static.lib *.obj
link /OUT:luac.exe luac.o print.o lua5.2-static.lib

If I just remove all references to print.o will there be a problem with what I compile when I try to embed this in my game? 如果我只是删除所有对print.o的引用,当我尝试将其嵌入到游戏中时,编译的内容是否会有问题?

In lua 5.1, under compiler you will see print.c , so I wonder if I should not do 5.2. 在lua 5.1中,在编译器下,您将看到print.c ,所以我想知道是否不应该执行5.2。

http://www.lua.org/source/5.1/ http://www.lua.org/source/5.1/

UPDATE UPDATE

So, what I did was change my build.bat and removed the print.obj, but I think the rename was useful in order to not include lua.obj and luac.obj in the .lib file, so I rename them and then rename them back. 因此,我要做的是更改build.bat并删除了print.obj,但是我认为重命名很有用,因为它不将lua.obj和luac.obj包含在.lib文件中,因此我将其重命名然后重命名他们回来。

cl /MD /O2 /W3 /c /DLUA_BUILD_AS_DLL *.c
del *.o
ren lua.obj lua.o
ren luac.obj luac.o
link /DLL /IMPLIB:lua5.2.lib /OUT:lua5.2.dll *.obj
link /OUT:lua.exe lua.o lua5.2.lib
lib /out:lua5.2-static.lib *.obj
ren lua.o lua.obj
ren luac.o luac.obj
link /OUT:luac.exe luac.obj lua5.2-static.lib

You don't need print.c in Lua 5.2, the only public function it defined is moved to luac.c . 在Lua 5.2中,您不需要print.c ,它定义的唯一公共函数被移至luac.c See PrintFunction() now found in luac.c . PrintFunction()现在发现luac.c

Also, it is not a good idea to rename .obj to .o in Windows. 同样,在Windows中将.obj重命名为.o也不是一个好主意。 Use whatever object file name is preferred by your tool chain. 使用工具链首选的任何对象文件名。

Edit: I now see the purpose of the renaming, and while it does work, I still think it is a bad practice. 编辑:现在,我看到了重命名的目的,尽管它确实起作用,但我仍然认为这是一种不好的做法。

The trick is that the CL command in your batch file is compiling every .c file in your current directory with identical options. 诀窍是,批处理文件中的CL命令将使用相同的选项编译当前目录中的每个.c文件。 As it happens, that isn't a problem, but it isn't a conventional way of doing this sort of thing. 碰巧的是,这不是问题,但这不是执行此类操作的常规方式。

Then, because a few of those files aren't actually part of the DLL you want to build, you rename those so that you can fit the rest on the LINK command line as a single wild card *.obj . 然后,由于其中一些文件实际上并不是您要构建的DLL的一部分,因此您将其重命名,以便将其余部分作为单个通配符*.obj放入LINK命令行中。

If you are going to use a batch file to build Lua yourself, then it would be better to list the .obj files that make up the DLL and each application on each relevant link line rather than depend on a wild card. 如果要使用批处理文件自己构建Lua,则最好在每个相关链接行上列出组成DLL和每个应用程序的.obj文件,而不要依赖于通配符。 As it is, if you had a build error in the CL command, you still build a DLL with all the rest of the objects, or worse, possibly with an out of date object for the file that didn't compile. 照原样,如果您在CL命令中遇到了构建错误,则仍然会使用所有其余对象来构建DLL,或更糟糕的是,可能会为未编译的文件使用过时的对象。

Then you might or might not successfully link lua.exe and luac.exe even though there were errors. 这样,即使出现错误,您也可能成功链接lua.exe和luac.exe。

The right answer here is to use a build tool of some form to compile and link. 正确的答案是使用某种形式的构建工具进行编译和链接。 Microsoft should have provided you NMake, it might have provided you their internal tool (used to drive builds of the Windows kernel and device drivers, I know it comes with the DDK tools but I think it is also in the Platform SDK and may be buried in VS) named BUILD, and there is always the option of adding a more broadly used build system such as GNU Make , CMAKE, or countless others. Microsoft应该已经为您提供了NMake,它可能已经为您提供了它们的内部工具(用于驱动Windows内核和设备驱动程序的构建,我知道它是DDK工具附带的,但是我认为它也包含在Platform SDK中,并且可能被掩埋了。在VS中称为BUILD),并且始终可以选择添加使用范围更广的构建系统,例如GNU Make ,CMAKE或无数其他构建系统。

If you insist on using the renaming trick because it is more expedient than learning to do it the right way right now, then please at least add some testing for the successful completion of each compile and link step with IF ERRORLEVEL 1 GOTO :EOF commands to end the batch file after a failure, as shown below. 如果您坚持使用重命名技巧是因为它比现在学习正确的方式更方便,那么请至少添加一些测试,以成功完成每个编译和链接步骤,并使用IF ERRORLEVEL 1 GOTO :EOF命令来完成。失败后结束批处理文件,如下所示。

As I edited the batch file, I notice another potential issue. 在编辑批处理文件时,我注意到另一个潜在的问题。 You built all the OBJ files with /DLUA_BUILD_AS_DLL , but then make a static library and link luac.exe from it. 您使用/DLUA_BUILD_AS_DLL构建了所有OBJ文件,但随后创建了一个静态库并从中链接luac.exe。 I don't know offhand what features of the source text are modified by that definition, but it probably isn't wise to make a static library from OBJ files compiled with it instead of a DLL. 我不知道该定义会修改源文本的哪些功能,但是从使用DLL而不是DLL编译的OBJ文件中创建静态库可能并不明智。

cl /MD /O2 /W3 /c /DLUA_BUILD_AS_DLL *.c
if ERRORLEVEL 1 goto :EOF
del *.o
ren lua.obj lua.o
ren luac.obj luac.o
link /DLL /IMPLIB:lua5.2.lib /OUT:lua5.2.dll *.obj
if ERRORLEVEL 1 goto :EOF
link /OUT:lua.exe lua.o lua5.2.lib
if ERRORLEVEL 1 goto :EOF
cl /MD /O2 /W3 /c *.c
if ERRORLEVEL 1 goto :EOF
del *.o
ren lua.obj lua.o
ren luac.obj luac.o
lib /out:lua5.2-static.lib *.obj
if ERRORLEVEL 1 goto :EOF
ren lua.o lua.obj
ren luac.o luac.obj
link /OUT:luac.exe luac.obj lua5.2-static.lib
if ERRORLEVEL 1 goto :EOF

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM