How to link Lua in Microsoft Visual C++.2010 Express?

寵の児 提交于 2019-12-11 11:07:25

问题


I am trying to write C++ classes/functions which can be accessed from Lua.

I need to export the C++ library as dll files.

I'm using Microsoft Visual C++.2010 Express

So I create a project and add the require .cpp files and .h files Now when I try to build, the following error occurs.

mylib.obj : error LNK2019: unresolved external symbol _lua_settop referenced in function "void __cdecl g_initializePlugin(struct lua_State *)" (?g_initializePlugin@@YAXPAUlua_State@@@Z)

Similar errors occur for all lua functions. When Googling I learnt that I had to link LUA.

How can that be done in Visual C++.

P.S I found a solution which directed me to give

#pragma comment( lib, "lua5.1" ) 

For this solution, it requires a lua5.1 file. From where should I download that file and where should it go (in the project folder?) ?


回答1:


OK! I figured out how!

To link Lua, the following has to be done after the C++ project has been created.

  • Copy C:\Program Files\Lua\5.1\lib\lua5.1.dll to your project folder
  • Copy C:\Program Files\Lua\5.1\lib\lua5.1.lib to your project folder
  • Right Click on Project --> Properties --> Configuration Properties --> Linker --> Input.
    • Add lua5.1.lib to Additional Dependencies
  • Right Click on Project --> Properties --> Configuration Properties --> VC++ Directories.
    • Add C:\Program Files\Lua\5.1\include to Include Directories

NOTE : my lua installation is in C:\Program Files\Lua\5.1

Now on building the project, dll file is created!



来源:https://stackoverflow.com/questions/10713674/how-to-link-lua-in-microsoft-visual-c-2010-express

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!