Error LNK2019: unresolved external symbol _luaJIT_setmode

I have this piece of code (luascript.cpp file):

bool LuaInterface::initState()
{
    m_luaState = luaL_newstate();
    if(!m_luaState)
        return false;

    luaL_openlibs(m_luaState);
#ifdef __LUAJIT__
    luaJIT_setmode(m_luaState, 0, LUAJIT_MODE_ENGINE | LUAJIT_MODE_ON);
#endif

    registerFunctions();
    if(!loadDirectory(getFilePath(FILE_TYPE_OTHER, "lib/"), false, true))
        std::clog << "[Warning - LuaInterface::initState] Cannot load " << getFilePath(FILE_TYPE_OTHER, "lib/") << std::endl;

    lua_newtable(m_luaState);
    lua_setfield(m_luaState, LUA_REGISTRYINDEX, "EVENTS");
    m_runningEvent = EVENT_ID_USER;
    return true;
}

      

declaration (luajit.h file):

LUA_API int luaJIT_setmode(lua_State *L, int idx, int mode);

      

and the error:

1>luascript.obj : error LNK2019: unresolved external symbol _luaJIT_setmode referenced in function "public: virtual bool __thiscall LuaInterface::initState(void)" (?initState@LuaInterface@@UAE_NXZ)
1>C:\Users\GUIAKI\Documents\trunk.r5918\vc10\Debug\tfs.exe : fatal error LNK1120: 1 unresolved externals

      

How can I solve it?

+3


source to share


2 answers


Just remove this line.



You cannot link to plain Lua if you keep it. And if you reference LuaJIT, the JIT compiler is enabled by default. This line of code is completely pointless.

+3


source


It looks like you forgot to link the library that is part of "luaJIT" (never heard of it or used it).

There should be a lib file that you should add to your project as an additional dependency (linker settings).



Also be aware to include the correct headers ("lua.hpp" for C ++, "luajit.h" for C).

+2


source







All Articles