Adding Luau to a CMake C project #1481
Replies: 2 comments 1 reply
-
You're going to want to update your CMAKELists.txt and main.c to align with the compatibility issues. Just putting my judgement based off a similar repo I saw for the Lua -> CPP embed try this?:
cmake_minimum_required(VERSION 3.10)
project(MyProject C)
set(CMAKE_C_STANDARD 23)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_COMPILER /usr/bin/clang-20)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
option(LUAU_BUILD_CLI "" OFF)
option(LUAU_BUILD_TESTS "" OFF)
option(LUAU_EXTERN_C "" ON)
add_subdirectory(extern/luau)
add_executable(main src/main.c)
target_link_libraries(main PUBLIC Luau.Compiler Luau.VM)
target_compile_definitions(main PRIVATE LUA_COMPAT_MODULE LUA_USE_LINUX)
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
int main(void) {
lua_State *lua = luaL_newstate();
luaL_openlibs(lua);
lua_close(lua);
return 0;
} |
Beta Was this translation helpful? Give feedback.
-
You're correct in thinking that I suggest trying to wrap the This should validate the fact that the
cmake_minimum_required(VERSION 3.10)
project(MyProject C)
set(LUAU_BUILD_CLI OFF)
set(LUAU_BUILD_TESTS OFF)
add_subdirectory(extern/luau)
target_compile_definitions(Luau.Compiler PUBLIC LUAU_EXTERN_C=1)
target_compile_definitions(Luau.VM PUBLIC LUAU_EXTERN_C=1)
set(CMAKE_C_STANDARD 23)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_COMPILER /usr/bin/clang-20)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_executable(main src/main.c)
target_link_libraries(main PUBLIC Luau.Compiler Luau.VM)
Let me know if this works for your setup. |
Beta Was this translation helpful? Give feedback.
-
Hello, I do not have a lot of experience with CMake. How do I add Luau to a project that uses C instead of C++?
My current CMakeLists.txt looks like this:
But this gives me the following error:
main.c:
extern/luau/VM/include/lualib.h:
Beta Was this translation helpful? Give feedback.
All reactions