Download

Trying to embed scripting (lua/python), can't link a static lib

Hello everyone,

I’m trying to embed a scripting solution (lua or python) in my game.

So far i haven’t had any luck with python, so i’m trying Lua, which has lighter and simpler sources.

The plan is to follow this wiki.

But unfortunately, LuaBinaries doesn’t seem to give a VC17 static lib.

So i tried to create my own static lib in visual studio 17.
I created a static lib project, added the lua sources and built.
I got my static lib.

Then, following the wiki i put the lib and the includes in some dir, and declared them in the build.cs:


// lua
PublicAdditionalLibraries.Add("../ThirdParty/LUA/StaticLUA.lib");
PublicIncludePaths.AddRange(new string] { "../ThirdParty/LUA/Includes" });

But when rebuilding i get this message:


LINK : fatal error LNK1181: cannot open input file '..\ThirdParty\LUA\StaticLUA.lib'

I got this with any static lib i could get my hands on, and pretty much the same with doing more or less the same with python (trying the embedded distribution, compiling cpython, etc.).

I get the same message even if i specify a file that doesn’t exist.

So i can’t even tell whether the linker can’t find the file or find it and can’t read it.

Additionnal include dirs are specified in the project properties and compilation goes well, so i guess the headers are found.
But somehow, the linker doesn’t want to hear of any static lib i try to feed it.

Any ideas ?

Thanks
Cedric

Ok for some reasons, PublicAdditionalLibraries doesn’t like relative path (btw, even “…/…/ThirdParty/LUA/StaticLUA.lib” didn’t work), the lib was found using this line:


PublicAdditionalLibraries.Add(ModuleDirectory + "/../../ThirdParty/LUA/StaticLUA.lib");

Now i’m facing another problem, the lib is found but it looks like the links are not done, i get this all around:


1>PythonActor.cpp.obj : error LNK2019: unresolved external symbol lua_tolstring referenced in function "public: static void __cdecl APythonActor::RunLua(class FString const &)" (?RunLua@APythonActor@@SAXAEBVFString@@@Z)
1>PythonActor.cpp.obj : error LNK2019: unresolved external symbol lua_pcallk referenced in function "public: static void __cdecl APythonActor::RunLua(class FString const &)" (?RunLua@APythonActor@@SAXAEBVFString@@@Z)
1>PythonActor.cpp.obj : error LNK2019: unresolved external symbol luaL_openlibs referenced in function "public: static void __cdecl APythonActor::RunLua(class FString const &)" (?RunLua@APythonActor@@SAXAEBVFString@@@Z)
1>PythonActor.cpp.obj : error LNK2019: unresolved external symbol luaL_loadstring referenced in function "public: static void __cdecl APythonActor::RunLua(class FString const &)" (?RunLua@APythonActor@@SAXAEBVFString@@@Z)
1>PythonActor.cpp.obj : error LNK2019: unresolved external symbol luaL_newstate referenced in function "public: static void __cdecl APythonActor::RunLua(class FString const &)" (?RunLua@APythonActor@@SAXAEBVFString@@@Z)
1>E:\ExportProject\TestPyhon\Binaries\Win64\UE4Editor-TestPyhon.dll : fatal error LNK1120: 5 unresolved externals

I’m going to look into this and will report here if i find a solution.

Cedric

All right, from the technical point of view it seems to work now.

The trick was just to specify the absolute path for the lib.

I couldn’t make my home made lib work (and that’s another problem) but using the VC15 static lib from luabinaries worked well, compilation and linking.

All is well, just another step in a long path.

Cheers
Cedric