c++ - 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": [
{
"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 移动到调试文件夹,但没有帮助。
解决方案
您正在混淆 32 位和 64 位。如果您的 gcc 构建 32 位可执行文件,那么您需要使用来自http://luabinaries.sourceforge.net/download.html的 32 位二进制文件,而不是 64 位二进制文件。当我故意将它们混合在一起时,我得到了你得到的确切错误,当我使用正确的错误时,它编译得很好。
推荐阅读
- amazon-web-services - AWS PHP 开发工具包 - Polly 神经语音 (NTTS)
- oracle - Oracle Service Cloud Chat 按engagementID 获取附件
- java - 无法设置 Test.APIKeyAuthToken
- java - spring boot 在第一次重试方法成功后执行第二次重试方法
- typescript - Sentry:beforeSend 被调用多次
- bitlocker - 开发像 bitlocker 这样的东西所需的技术
- c - 使用管道在Unix中同步N个子进程以打印消息
- algorithm - 使用动态 FPS 在游戏引擎中渲染视频
- java - 其他人使用的功能 - 如何导出以不暴露代码
- java - 如何从strings.xml获取值到arraylist