lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


One more thing!

I had to lie to LuaJIT that it's compiling with _MSC_VER less than 1400, otherwise it would use ftelli64 which is not available on the XP msvcrt.dll (it is in Vista), hence the

> echo cl.exe /D_MSC_VER=1399 %%* > cl.cmd

Here is what happens if I let cl.exe execute normally:

   Creating library lua51.lib and object lua51.exp
ljamalg.obj : error LNK2019: unresolved external symbol __imp___ftelli64 referenced in function _lj_cf_io_method_seek
lua51.dll : fatal error LNK1120: 1 unresolved externals

As a different workaround I've thought of using telli64(fileno(x)) - but it's actually not correct if the file is buffered (and in general not). telli64 exists there... (you need Windows XP and depends.exe on c:\windows\system32\msvcrt.dll really to tell)

This off course makes the luajit to lose it's ability to read files bigger than 4GB which might be problematic, not for me yet :)

Thanks,
Dimiter "malkia" Stanev.

On 6/29/2011 5:58 PM, Dimiter "malkia" Stanev wrote:
Hi group,

So I wanted to move my project to use MSVCRT.DLL for LuaJIT (but the
it's also related to lua, and Windows in general).

With VS2008, VS2010 that is no longer possible, but after some googling
I found this wonderful page:

http://kobyk.wordpress.com/2007/07/20/dynamically-linking-with-msvcrtdll-using-visual-c-2005/


The solution is to use WDK and link to msvcrt_2000.obj (32-bit only).

More clues on google:
http://www.google.com/search?q=%22msvcrt_win2000.obj%22

Whether it's safe or not, I can't tell. But it works for on my laptop
with Windows XP (actually bootcamped MacBook), and at work Vista 64
Business and Windows 7.

Here is the file that I'm compiling luajit with (it could work for other
things too).

----------------------------------------------------------------------

rem This is
rem E:\p\ufo\build\Windows\luajit-wdk.cmd
rem
rem Assuming LuaJit (2.00+) is here:
rem E:\p\luajit
rem
rem and that these folders exists
rem E:\p\ufo\bin\Windows\x86
rem E:\p\ufo\bin\Windows\x64
rem
rem also assumes that the Windows DDK is located here
rem (change it, or provided as second parameter):
rem e:\apps\wdk
rem
rem and that lua is installed and on the PATH (I've used cygwin one)
rem if not - just remove the line where I'm deleteing buildvm-*.h files
rem
rem First parameter to the batch file is 32 or 64

@echo off
setlocal

set _UFODIR=%~dp0..\..
set _LUAJITDIR=%_UFODIR%\..\luajit\src
set _ARCH=%1
set _WDK=%2

if "%_ARCH%"=="" set _ARCH=32
if "%_WDK%"=="" set _WDK=e:\apps\wdk
if "%_ARCH%"=="32" set _TARGET=i386
if "%_ARCH%"=="32" set _LUA_ARCH=x86
if "%_ARCH%"=="64" set _TARGET=amd64
if "%_ARCH%"=="64" set _LUA_ARCH=x64
if "%_TARGET%"=="" (
echo You should specify 32 or 64 as first argument
goto :EOF
)

set _CROSS_TARGET=
if "%_TARGET%"=="amd64" set _CROSS_TARGET=x32-64

echo Compiling LuaJIT: [_ARCH=%_ARCH%] [_TARGET=%_TARGET%]
[_CROSS_TARGET=%_CROSS_TARGET%]
call %_WDK%\bin\setenv.bat %_WDK% fre %_CROSS_TARGET% win7 no_oacr

set LIB=%BASEDIR%\lib\crt\%_TARGET%;%BASEDIR%\lib\win7\%_TARGET%;%LIB%
set INCLUDE=%CRT_INC_PATH%;%INCLUDE%;

pushd %_LUAJITDIR%
del *.obj buildvm_*.h 1>nul 2>nul
del link.cmd cl.cmd 1>nul 2>nul
echo cl.exe /D_MSC_VER=1399 %%* > cl.cmd
if "%_TARGET%"=="i386" echo link.exe
%_WDK%\lib\win7\%_TARGET%\msvcrt_win2000.obj %%* > link.cmd
call msvcbuild amalg
del link.cmd cl.cmd 1>nul 2>nul
git log -1 >> lua51.dll
git log -1 >> luajit.exe
call :install lua51.dll %_UFODIR%\bin\Windows\%_LUA_ARCH%
call :install luajit.exe %_UFODIR%\bin\Windows\%_LUA_ARCH%
popd
goto :EOF

:install
echo install: [move /y %*]
move /y %*
goto :EOF

----------------------------------------------------------------------

Also this ugly diff (on my side). Unfortunately if batch file is to be
called it has to be.... ahem "call"-ed (my cl.bat that later calls
cl.exe is such)

----------------------------------------------------------------------

E:\p\luajit\src>git diff msvcbuild.bat
diff --git a/src/msvcbuild.bat b/src/msvcbuild.bat
index c7e5df6..b718a8a 100644
--- a/src/msvcbuild.bat
+++ b/src/msvcbuild.bat
@@ -14,8 +14,8 @@
@if not defined INCLUDE goto :FAIL

@setlocal
-@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE
-@set LJLINK=link /nologo
+@set LJCOMPILE=call cl /nologo /c /MD /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE
+@set LJLINK=call link /nologo
@set LJMT=mt /nologo
@set LJLIB=lib /nologo
@set DASMDIR=..\dynasm

Thanks,
Dimiter "malkia" Stanev.