Lua库无法链接

当我尝试执行以下代码时,我收到undefined reference to 'luaL_openlibs'的错误

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

int main(int argc, char *argv[])
{

    lua_State *L = luaL_newstate();
    luaL_openlibs(L);
    return 0;
}

这是我的VSCode tasks文件:

{
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: g++.exe build active file",
            "command": "C:/MinGW/bin/g++.exe",
            "args": [
                "-g",
                "${workspaceFolder}\\src\\**.cpp",
                "-L",
                "${workspaceFolder}\\lib",
                "-o",
                "${workspaceFolder}\\debug\\game.exe",
                "-llua54"
            ],
            "options": {
                "cwd": "C:/MinGW/bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ],
    "version": "2.0.0"
}

这些是我的文件

.
├── .vscode
│   ├── c_cpp_properties.json
│   └── launch.json
│   └── settings.json
│   └── tasks.json
├── debug
├── lib
│   ├── lauxlib.h
│   └── lua.h
│   └── lua.hpp
│   └── luaconf.h
│   └── lualib.h
│   └── liblua54.dll
│   └── liblua54.a
├── src
│   ├── main.cpp

我已经指定编译器的所有必要参数。我是一个链接库的完全初学者,不知道我缺少什么。我还尝试将liblua54.a和liblua54.dll移动到debug文件夹中,但没有帮助。

点赞
用户12917919
用户12917919

我期望将以下内容添加到上面的 args 中可以帮助解决问题:

...
"${workspaceFolder}\\lua",
"-l",
"-llua56",
 "-o",
...
2020-11-15 15:39:12
用户7509065
用户7509065

你把32位和64位搞混了。如果你的GCC生成32位的可执行文件,那么你需要使用从http://luabinaries.sourceforge.net/download.html下载的32位二进制文件,而不是64位的。当我故意混淆它们时,我得到了你正在遇到的确切错误,而当我使用正确的二进制文件时,编译顺利完成。

2020-11-16 23:38:54