嵌入式Lua不会打印到分配的控制台

嵌入式Lua不会打印到分配的控制台

本文介绍了嵌入式Lua不会打印到分配的控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码看起来像(Windows平台):

My code looks like that (Windows platform):

 c> 

It is possible if stdout in main() is not the same as stdout in luaB_print().

是全局变量,链接器应该使它们相同,对吗?

But both are global variables, and the linker is supposed to make them be the same, right?

好吧,不一定。全局变量 stdout 是C运行时库的一部分。如果Lua核心链接到与程序不同的C运行时DLL,那么Lua核心和程序实际上可能指的是不同的变量 stdout 。

Well, not necessarily. The global variable stdout is part of the C runtime library. If the Lua core is linked to a different C runtime DLL than the program, then it is possible that Lua core and the program are in fact referring to different variables named stdout.

使用显示我的测试可执行文件链接到MSVCRT.DLL(MinGW喜欢的C运行时),但来自Lua for Windows的 lua5.1.dll MSVCR80.DLL(Visual Studio 2005中的C运行时)。

A quick check with Dependency Walker shows that my test executable was linked against MSVCRT.DLL (the C runtime preferred by MinGW), but the lua5.1.dll from Lua for Windows is linked against MSVCR80.DLL (the C runtime from Visual Studio 2005).

这个问题很容易解决。我改变了我的测试用例链接对建立的Lua链接对MSVCRT.DLL,现在原来的代码工作原样。这里是新的构建步骤,现在在BAT文件中,并假设 lua5_1-4_Win32_dll6_lib 包含正确构建的Lua核心:

This problem is easily resolved. I changed my test case to link against a build of Lua linked against MSVCRT.DLL, and now the original code works as intended. Here's the new build steps, now found in a BAT file, and assuming that lua5_1-4_Win32_dll6_lib contains the correctly built Lua core:

setlocal
set LUADIR="lua5_1_4_Win32_dll6_lib"
gcc -o q15787892 q15787892.c -mwindows -I"%LUADIR%\include" "%LUADIR%\lua5.1.dll"
if not exist lua5.1.dll copy %LUADIR%\lua5.1.dll .

这篇关于嵌入式Lua不会打印到分配的控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-13 14:03