I'm trying to use Lua embedded in C using the CLion IDE and CMake, but I'm running into linker errors.
When running this program, I get undefined symbol: _luaL_newstate
:
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
int main()
{
lua_State *L = luaL_newstate();
return 0;
}
This is my CMake file, it uses CMake's built in FindLua.cmake to find the package. I'm using the CMake options -DCMAKE_CXX_FLAGS="-Wall -Wextra" -DCMAKE_C_FLAGS="-Wall -Wextra"
.
Edit: The linker command generated by CMake that's failing is lld-link.exe /nologo @CMakeFiles\LuaProjk.dir\objects1.rsp /out:C:\Users\b\CLionProjects\LuaProjk\bin\LuaProjk.exe /implib:LuaProjk.lib /pdb:C:\Users\b\CLionProjects\LuaProjk\bin\LuaProjk.pdb /version:0.0 /machine:X86 /debug /INCREMENTAL /subsystem:console C:\Lua\lua54.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\LuaProjk.dir/intermediate.manifest CMakeFiles\LuaProjk.dir/manifest.res
cmake_minimum_required(VERSION 3.17)
project(LuaProjk C)
set(LUA_DIR /Lua)
set(LUA_INCLUDE_DIR /Lua/include)
find_package(Lua REQUIRED)
include_directories(${LUA_INCLUDE_DIR})
set(CMAKE_C_STANDARD 11)
set(SOURCE_FILES main.c)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ../../bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ../../lib)
add_executable(LuaProjk ${SOURCE_FILES})
target_link_libraries(LuaProjk ${LUA_LIBRARIES})
The Lua directory contains the lua54.dll and lua54.lib files, as well as the include directory with all the headers.
Am I missing something? Thanks for any help!