使用Makefile无法运行简单的嵌入式Lua脚本

我正在尝试设置CMake,以便使用MinGW-w64在Windows 10上与Visual Studio '22配合使用生成Makefile,但是在使用Makefile编译并尝试运行测试应用程序时出现错误。 它打印了embed.c中指定的文本,但没有打印script.lua中的文本。 有没有办法修复这个问题?

我也不理解控制台对此的说法:

In function 'main':
C:/MyLibs/lua-5.1/include/lauxlib.h:112:31: warning: value computed is not used [ -Wunused-value]
112 |     (luaL_loadfi1e(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))

<squiggle is under the ||>

D: \Programming\Misc_Lua\embed\embed.c:18:5: note: in expansion of macro 'luaL_dofile'
18 |       luaL_dofile(L, "script.lua");

<squiggle is under the luaL_dofile>

这是script.lua:

-- script.lua
print("Hello, World from File")

这是embed.c:

#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>

#include "EmbedConfig.h"

int main(int argc, char ** argv) {

    lua_State *L = luaL_newstate();
    luaL_openlibs(L);

    //open a Lua file:
    printf("This line in directly from C\n\n");
    luaL_dofile(L, "script.lua");
    printf("\nBack to C again\n\n");

    lua_close(L);
    return 0;
}

这是CMakeLists.txt:

cmake_minimum_required(VERSION 3.15)

# set the project name and version
project(Embed VERSION 1.0)

find_package(Lua51 REQUIRED)

# configure a header file to pass the version number only
configure_file(EmbedConfig.h.in EmbedConfig.h)

# add the executable
add_executable(Embed embed.c)

# add the binary tree to the search path for include files
# so that we will find EmbedConfig.h
target_link_libraries(Embed "${LUA_LIBRARIES}")
target_include_directories(Embed PUBLIC "${PROJECT_BINARY_DIR}" "${LUA_INCLUDE_DIR}")

# add the install targets
install(TARGETS Embed DESTINATION bin)
install(FILES "${PROJECT_BINARY_DIR}/EmbedConfig.h"
  DESTINATION include
  )

include(InstallRequiredSystemLibraries)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
set(CPACK_PACKAGE_VERSION_MAJOR "${Embed_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${Embed_VERSION_MINOR}")
include(CPack)

原文链接 https://stackoverflow.com/questions/70298996

点赞