简体   繁体   English

无法将Lua for Windows嵌入到C ++程序中

[英]Having trouble embedding Lua for Windows install into C++ program

This is the first question I have found myself not being able to get to the bottom of using my normal googling/stack overflowing/youtubing routine. 这是我发现自己无法使用正常的谷歌搜索/堆栈溢出/ youtubing例程的第一个问题。

I am trying to compile a minimal Lua program inside of a C++ environment just to ensure my environment is ready to development. 我正在尝试在C ++环境中编译一个最小的Lua程序,以确保我的环境已经准备好开发。 The Lua language will be later used for User Interface programming for my C++ game. Lua语言稍后将用于我的C ++游戏的用户界面编程。

First some basic information on my environment: 首先是一些关于我环境的基本信息:

Windows 7 64-bit Windows 7 64位

Visual studio 2010 Visual Studio 2010

Lua for Windows 5.1 (latest build I could download from google code) Lua for Windows 5.1(我可以从谷歌代码下载的最新版本)

Here is the code I am trying to compile: 这是我试图编译的代码:

// UserInt.cpp : Defines the entry point for the console application.
//
#pragma comment(lib,"lua5.1.dll")
#include "stdafx.h"
#ifndef __LUA_INC_H__
#define __LUA_INC_H__

extern "C"
{
   #include "lua.h"
   #include "lauxlib.h"
   #include "lualib.h"
}



int _tmain(int argc, _TCHAR* argv[])
{
    lua_State * ls = luaL_newstate();
    return 0;
}

#endif // __LUA_INC_H__

Here is the Error I am getting: 这是我得到的错误:

1>UserInt.obj : error LNK2019: unresolved external symbol _luaL_newstate referenced in function _wmain 1>c:\\users\\deank\\documents\\visual studio 2010\\Projects\\UserInt\\Debug\\UserInt.exe : fatal error LNK1120: 1 unresolved externals

Things I have tried: 我尝试过的事情:

I have read about lua_open()(and several other functions) no longer being used so I tried the newstate function instead. 我已经读过关于lua_open()(以及其他一些函数)不再使用的内容,所以我尝试了newstate函数。 I get the same error. 我犯了同样的错误。 This was more of a sanity check than anything. 这比任何事都更像是一种理智的检查。 I am using 5.1 and not 5.2 so I do not think this really matters. 我使用5.1而不是5.2,所以我认为这不重要。

I have also read this thread Cannot link a minimal Lua program but it does not seem to help me because I am not running the same environment as that OP. 我也读过这个帖子无法链接一个最小的Lua程序,但它似乎没有帮助我,因为我没有运行与OP相同的环境。 I am on a simple windows 7 and visual studio environment. 我在一个简单的Windows 7和视觉工作室环境。

The top pragma comment line was something I saw in yet another thread. 顶部的pragma注释行是我在另一个帖子中看到的。 I get the same error with or without it. 无论有没有,我都会得到同样的错误。

I have gone into my visual studio C++ directories area and added the lua include to the includes and the lua lib to the libraries. 我已进入我的visual studio C ++目录区域,并将lua include添加到includes和lua lib到库。

So it seems like my program is seeing the .h and seeing the symbol. 所以看起来我的程序正在看到.h并看到符号。 But for some reason it is not getting the .cpp implementation for the functions. 但由于某种原因,它没有获得函数的.cpp实现。 This is why I was hoping including that .dll directly would help fix the problem, but it hasn't. 这就是为什么我希望包含.dll直接有助于解决问题,但事实并非如此。

So, I feel like I have exhausted all of my options solving this on my own. 所以,我觉得我已经用尽了所有我自己解决这个问题的选择。 I hope someone is able to help me move forward here. 我希望有人能够帮助我在这里前进。 Lua looks like an awesome language to script in and I would like to get my environment squared away for development. Lua看起来像是一个很棒的语言来编写脚本,我想让我的环境平稳地进行开发。

I hope it is just some silly error on my part. 我希望这只是我的一些愚蠢的错误。 I believe I have provided as much information as I can. 我相信我提供了尽可能多的信息。 If you need more specifics I will update with info if I can provide it. 如果您需要更多细节,我会更新信息,如果我能提供。

Edit1 EDIT1

Tried the solution in this Can't build lua a project with lua in VS2010, library issue suspected 尝试了这个解决方案无法在VS2010中用lua构建lua项目,怀疑库问题

That did not work either. 那也行不通。

You'll need to have the library (.LIB) file and add that to VS. 您需要拥有库(.LIB)文件并将其添加到VS. Use Project > Properties and go to Linker > Input and add the full .lib filename to the "Additional Dependencies" line. 使用Project> Properties并转到Linker> Input并将完整的.lib文件名添加到“Additional Dependencies”行。 Note that the .LIB is different from the .DLL. 请注意,.LIB与.DLL不同。

Personally, I prefer adding the source code to my project, over referencing the dynamic link library. 就个人而言,我更喜欢将源代码添加到我的项目中,而不是引用动态链接库。 The following procedure will let you do as such. 以下程序将允许您这样做。

  1. Download the source code ( http://www.lua.org/ftp/ ), uncompress it. 下载源代码( http://www.lua.org/ftp/ ),解压缩。

  2. In Visual Studio, choose File > New > Project and choose Visual C++, Win32, "Win32 Console Application". 在Visual Studio中,选择“文件”>“新建”>“项目”,然后选择“Visual C ++”,“Win32”,“Win32控制台应用程序”。

  3. In your project in Visual Studio, add all the source code, except luac.c. 在Visual Studio的项目中,添加除luac.c之外的所有源代码。 Also delete the main() function out of the file that VS created for you. 同时从VS为您创建的文件中删除main()函数。 This is usually given the name of the project you specified with the .cpp file extension. 这通常是您使用.cpp文件扩展名指定的项目的名称。 You could just remove this file all-together from the project. 您可以从项目中一起删除此文件。

  4. Build and Run. 构建并运行。

This is the Lua console 这是Lua控制台

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM