0

How can I compile the file for the linker in visual studio 2010.

These are the steps I follow with Lua 5.2.1 source code with Visual Studio 2010:

  1. cl /MD /O2 /c /DLUA_BUILD_AS_DLL *.c
  2. Rename "lua.obj" and "luac.obj" with the extention ".o" Sso they won't be selected
  3. link /DLL /IMPLIB:lua5.2.lib /OUT:lua5.2.dll *.obj
  4. link /OUT:lua.exe lua.o lua5.2.lib
  5. lib /OUT:lua5.2-static.lib *.obj
  6. link /OUT:luac.exe luac.o lua5.2-static.lib

From all the above steps, i pick the lua5.2.lib and add it to the linker as shown below:

enter image description here

When I compile the following C code with Dev-C++, it does not give any error but when i call it from Lua with require command, it says it cannot find it.

#include<windows.h>
#include<math.h>
#include "lauxlib.h"
#include "lua.h"


#define LUA_LIB   int __declspec(dllexport)



static int IdentityMatrix(lua_State *L)
{
    int in = lua_gettop(L);
    if (in!=1)
    {
       lua_pushstring(L,"Maximum 1 argument");
       lua_error(L);
    }
    lua_Number n = lua_tonumber(L,1);
    lua_newtable(L);                  /*                 tabOUT n */
    int i,j;
    for (i=1;i<=n;i++)
    {
        lua_newtable(L);              /*         row(i) tabOUT n */
        lua_pushnumber(L,i);          /*       i row(i) tabOUT n */
        for (j=1;j<=n;j++)
        {
            lua_pushnumber(L,j);      /*     j i row(i) tabOUT n */
            if (j==i)
            {
                lua_pushnumber(L,1);
            }
            else                      /* 0/1 j i row(i) tabOUT n */
            {
                lua_pushnumber(L,0);
            }
            /*  Put 0/1 inside row(i) at j position */
            lua_settable(L,-4);       /*       i row(i) tabOUT n */
        }
        lua_insert(L,-2);             /*       row(i) i tabOUT n */
        lua_settable(L,2);            /*                tabOUT n */
    }
    return 1;
}


static const struct luaL_Reg LuaMath [] = {{"IdentityMatrix", IdentityMatrix},
                                           {            NULL,           NULL}};

LUA_LIB luaopen_LuaMath(lua_State *L)
{
    luaL_newlib(L,LuaMath);
    return 1;
}

When I run this simple Lua code:

require("LuaMath")

A=LuaMath.IdentityMatrix(4)

The error writes

error loading module 'LuaMath' from file './LuaMath.dll': impossible to find the specified module'.

Any help?

Azoun
  • 255
  • 3
  • 14

0 Answers0