I'm trying to add Lua to the project, but when I compile it I get an error:

LuaScript.cpp :(. Text + 0xf4): undefined reference to luaL_loadfilex

CMakeLists.txt:

cmake_minimum_required(VERSION 2.8) project(Linaria) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/) set(CMAKE_C_COMPILER_INIT g++) find_package(SFML 2 REQUIRED system window graphics network audio) find_package(Lua REQUIRED) include_directories( ${SFML_INCLUDE_DIR} ${LUA_INCLUDE_DIR} include/ ) file(GLOB SRC "src/*.cpp" ) add_executable(Linaria ${SRC}) target_link_libraries(Linaria ${SFML_LIBRARIES} ${LUA_LIBRARIES} ) set_target_properties(Linaria PROPERTIES OUTPUT_NAME "Linaria" CLEAN_DIRECT_OUTPUT 1 ) add_definitions(-std=c++11 -w) 

And here is the code:

 void LuaScript::open(std::string file){ if(!this->luaState){ this->luaState = luaL_newstate(); if(luaL_loadfile(this->luaState, file.c_str())){ // File not found } luaL_openlibs(this->luaState); } } } 

Nowhere did I find anything that would solve the error.

What to do?

  • one
    undefined reference often says that the corresponding library is not connected (by linker). Maybe the version is not the same, or bit. - αλεχολυτ
  • one
    perhaps you need to connect not only lua , but also lualib . - aleksandr barakin
  • added to CMakeLists.txt -llua5.2 -llualib5.2 , but nothing has changed. - user26699
  • one
    Do you have this liblua (lualib) library of the required version? for reference: in order for a user to receive notification of comments in a discussion where there is more than one responder, you must explicitly mention this user ( @пользователь ). - aleksandr barakin
  • @alexanderbarakin, yes, I have the lua 5.2 library installed - user26699

0