1 year ago
#388597
Leandro Czbr
couldn't create a lua module in C++ (can't include local header)
I'm using vs code and g++ to compile c++, however I can't include lua.h
, lauxlib.h
, lualib.h
etc.
this is the terminal (using vscode terminal):
C:\MingW\bin> .\g++ C:\Users\leand\Desktop\VSCODE\cpp\template.cpp -o C:\Users\leand\Desktop\VSCODE\cpp\build.exe -I C:\Users\leand\Desktop\VSCODE\cpp\
C:\Users\leand\AppData\Local\Temp\cc6kM8pM.o:template.cpp:(.text+0x1d): undefined reference to `lua_tonumberx'
C:\Users\leand\AppData\Local\Temp\cc6kM8pM.o:template.cpp:(.text+0x3b): undefined reference to `lua_tonumberx'
C:\Users\leand\AppData\Local\Temp\cc6kM8pM.o:template.cpp:(.text+0x59): undefined reference to `lua_pushnumber'
C:\Users\leand\AppData\Local\Temp\cc6kM8pM.o:template.cpp:(.text+0x9f): undefined reference to `luaL_checkversion_'
C:\Users\leand\AppData\Local\Temp\cc6kM8pM.o:template.cpp:(.text+0xba): undefined reference to `lua_createtable'
C:\Users\leand\AppData\Local\Temp\cc6kM8pM.o:template.cpp:(.text+0xd4): undefined reference to `luaL_setfuncs'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
this is the folder (C:\Users\leand\Desktop\VSCODE\cpp)
this is my code
#ifdef __cplusplus
extern "C" {
#endif
#include "luaconf.h"
#include "lualib.h"
#include "lauxlib.h"
#include "lua.h"
int soma(lua_State *L) {
double nl = lua_tonumber(L, 1);
double n2 = lua_tonumber(L, 2);
double resultado = nl + n2;
lua_pushnumber(L, resultado); /* Empurra para o stack do Lua o valor resultado return 1; /* Informa quantas variáveis estão sendo retornadas para o Lua */
return 1; // quantas variaveis retornam para o Lua
}
int luaopen_template(lua_State *L){ /* lua_State *L é um tipo de ponteiro específico para a API do Lua */
luaL_Reg funcoes[] = { /* Recurso para listar funções C que devem ser levadas para o Lua */
{"soma", soma},
{NULL, NULL} /* Indicador que a lista acabou */
};
luaL_newlib(L, funcoes); /* Define uma nova biblioteca Lua com as funções passadas por Lual_Reg */
return 1;
}
#ifdef __cplusplus
}
#endif
c++
include
include-path
0 Answers
Your Answer