简体   繁体   English

尝试使用mingw构建和编译lua 5.3.3,未定义参考错误

[英]trying to build and compile lua 5.3.3 with mingw , undefined reference error

SO basically i got the lua5.3.3 source code and i am trying to build it with mingw 所以基本上我得到了lua5.3.3源代码,我正在尝试使用mingw构建它

what i have done so far is that i did the whole operation in msys and then copied over the lib files and bin files and include files to mingw appropriate folders 到目前为止,我所做的是我在msys中完成了整个操作,然后将其复制到lib文件和bin文件中,并将文件包含到mingw适当的文件夹中

however when i try to actually compile an application that uses it, i get these errors 但是,当我尝试实际编译使用它的应用程序时,出现这些错误

this is the command i used to compile my program that uses lua 这是我用来编译使用lua的程序的命令

gcc syx.cpp -llua

C:\Users\User\AppData\Local\Temp\cckJPF8N.o:syx.cpp:(.text+0xf): undefined reference to `luaL_newstate()'
C:\Users\User\AppData\Local\Temp\cckJPF8N.o:syx.cpp:(.text+0x21): undefined reference to `luaL_openlibs(lua_State*)'
C:\Users\User\AppData\Local\Temp\cckJPF8N.o:syx.cpp:(.text+0x3e): undefined reference to `luaL_loadfilex(lua_State*, char const*, char const*)'
C:\Users\User\AppData\Local\Temp\cckJPF8N.o:syx.cpp:(.text+0x77): undefined reference to `lua_pcallk(lua_State*, int, int, int, int, int (*)(lua_State*, int, int))'
C:\Users\User\AppData\Local\Temp\cckJPF8N.o:syx.cpp:(.text+0x87): undefined reference to `lua_close(lua_State*)'
collect2.exe: error: ld returned 1 exit status

and here is the file(very basic) in case you need to see it 这是文件(非常基本),以防您需要查看

#include <stdio.h>

#include <lua5.3/lua.h>
#include <lua5.3/lualib.h>
#include <lua5.3/lauxlib.h>

/* the Lua interpreter */
lua_State* L;

int main ( int argc, char *argv[] )
{
   L = luaL_newstate();

   luaL_openlibs(L);

   luaL_dofile(L, "test.lua");

   /* cleanup Lua */
   lua_close(L);

        return 0;
}

i know the library file exists since it was created with mingw namely liblua.a which sits in my mingw lib folder , as well as the other files related to lua such as lua.exe luac.exe the include files etc so i am not sure what else is missing 我知道该库文件存在,因为它是用mingw创建的,即liblua.a,它位于我的mingw lib文件夹中,还有其他与lua相关的文件,例如lua.exe luac.exe包括文件等,所以我不确定还有什么缺失

Okay i found the solution 好吧,我找到了解决方案

turns out gcc is mangling the symbols from the library header(whatever that means) 事实证明gcc正在从库头中破坏符号(无论这意味着什么)

what needs to be done is the headers need to be wrapped in a extern "C" {//headers} to make it work 需要做的是将标头包裹在extern“ C” {// headers}中以使其起作用

reference is here : 参考在这里:

http://www.linuxquestions.org/questions/programming-9/undefined-reference-error-when-using-lua-api-892782/ http://www.linuxquestions.org/questions/programming-9/undefined-reference-error-when-using-lua-api-892782/

and just to be clear, here is a working example: 为了清楚起见,这是一个有效的示例:

#include <stdio.h>

extern "C"{
#include <lua5.3/lua.h>
#include <lua5.3/lualib.h>
#include <lua5.3/lauxlib.h>
}

/* the Lua interpreter */
lua_State* L;

int main ( int argc, char *argv[] )
{
   L = luaL_newstate();

   luaL_openlibs(L);

   luaL_dofile(L, "test.lua");

   /* cleanup Lua */
   lua_close(L);

        return 0;
}

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

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