[求助] lua 源码 移植

cqh963852
Posts: 10
Joined: Fri Dec 11, 2020 1:17 pm

[求助] lua 源码 移植

Postby cqh963852 » Sun Dec 20, 2020 5:24 pm

我从 examples 里面复制了一个 hello_world 项目,可以正常运行。之后我想将lua 作为 一个组件引入 hello_world。
但是在构建过程中提示找不到头文件。

Code: Select all

Scanning dependencies of target __idf_main
[ 99%] Building C object esp-idf/main/CMakeFiles/__idf_main.dir/hello_world_main.c.obj
/home/cqh/workspace/hello_world/main/hello_world_main.c:15:10: fatal error: lauxlib.h: No such file or directory
 #include "lauxlib.h"
          ^~~~~~~~~~~
compilation terminated.
esp-idf/main/CMakeFiles/__idf_main.dir/build.make:62: recipe for target 'esp-idf/main/CMakeFiles/__idf_main.dir/hello_world_main.c.obj' failed
make[2]: *** [esp-idf/main/CMakeFiles/__idf_main.dir/hello_world_main.c.obj] Error 1
CMakeFiles/Makefile2:5476: recipe for target 'esp-idf/main/CMakeFiles/__idf_main.dir/all' failed
make[1]: *** [esp-idf/main/CMakeFiles/__idf_main.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2
make failed with exit code 2
因为 lua 源码里面只有makefile,所以我想采用 externalproject_add 的方式。

我的目录结构如下

Code: Select all

.
├── CMakeLists.txt
├── Makefile
├── README.md
├── components
│   └── esp32_lua
│       ├── CMakeLists.txt
│       ├── Kconfig
│       ├── hello_world.lua
│       └── lua
│           ├── all
│           ├── lapi.c
│           ├── lapi.h
│           ├── lauxlib.c
│           ├── lauxlib.h
│           ├── lbaselib.c
│           ├── lcode.c
│           ├── lcode.h
│           ├── lcorolib.c
│           ├── lctype.c
│           ├── lctype.h
│           ├── ldblib.c
│           ├── ldebug.c
│           ├── ldebug.h
│           ├── ldo.c
│           ├── ldo.h
│           ├── ldump.c
│           ├── lfunc.c
│           ├── lfunc.h
│           ├── lgc.c
│           ├── lgc.h
│           ├── linit.c
│           ├── liolib.c
│           ├── ljumptab.h
│           ├── llex.c
│           ├── llex.h
│           ├── llimits.h
│           ├── lmathlib.c
│           ├── lmem.c
│           ├── lmem.h
│           ├── loadlib.c
│           ├── lobject.c
│           ├── lobject.h
│           ├── lopcodes.c
│           ├── lopcodes.h
│           ├── lopnames.h
│           ├── loslib.c
│           ├── lparser.c
│           ├── lparser.h
│           ├── lprefix.h
│           ├── lstate.c
│           ├── lstate.h
│           ├── lstring.c
│           ├── lstring.h
│           ├── lstrlib.c
│           ├── ltable.c
│           ├── ltable.h
│           ├── ltablib.c
│           ├── ltests.c
│           ├── ltests.h
│           ├── ltm.c
│           ├── ltm.h
│           ├── lua.c
│           ├── lua.h
│           ├── luaconf.h
│           ├── lualib.h
│           ├── lundump.c
│           ├── lundump.h
│           ├── lutf8lib.c
│           ├── lvm.c
│           ├── lvm.h
│           ├── lzio.c
│           ├── lzio.h
│           ├── makefile
│           ├── manual
│           │   ├── 2html
│           │   └── manual.of
│           ├── onelua.c
│           └── testes
│               ├── all.lua
│               ├── api.lua
│               ├── attrib.lua
│               ├── big.lua
│               ├── bitwise.lua
│               ├── bwcoercion.lua
│               ├── calls.lua
│               ├── closure.lua
│               ├── code.lua
│               ├── constructs.lua
│               ├── coroutine.lua
│               ├── cstack.lua
│               ├── db.lua
│               ├── errors.lua
│               ├── events.lua
│               ├── files.lua
│               ├── gc.lua
│               ├── gengc.lua
│               ├── goto.lua
│               ├── heavy.lua
│               ├── libs
│               │   ├── P1
│               │   │   └── dummy
│               │   ├── lib1.c
│               │   ├── lib11.c
│               │   ├── lib2.c
│               │   ├── lib21.c
│               │   ├── lib22.c
│               │   └── makefile
│               ├── literals.lua
│               ├── locals.lua
│               ├── main.lua
│               ├── math.lua
│               ├── nextvar.lua
│               ├── packtests
│               ├── pm.lua
│               ├── sort.lua
│               ├── strings.lua
│               ├── tpack.lua
│               ├── utf8.lua
│               ├── vararg.lua
│               └── verybig.lua
├── main
│   ├── CMakeLists.txt
│   ├── component.mk
│   └── hello_world_main.c
└── sdkconfig
components/esp32_lua/CMakeLists.txt 如下

Code: Select all

cmake_minimum_required(VERSION 3.5)

idf_component_register()

externalproject_add(lua_build
    PREFIX ${COMPONENT_DIR}
    SOURCE_DIR ${COMPONENT_DIR}/lua
    CONFIGURE_COMMAND ""
    BUILD_IN_SOURCE 1
    BUILD_COMMAND make liblua.a
    INSTALL_COMMAND ""
    )

add_library(lua STATIC IMPORTED GLOBAL)
add_dependencies(lua lua_build)

set_target_properties(lua PROPERTIES IMPORTED_LOCATION
    ${COMPONENT_DIR}/lua/liblua.a)

set_target_properties(lua PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
    ${COMPONENT_DIR}/lua)

set_directory_properties( PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
    "${COMPONENT_DIR}/lua/liblua.a")
main/hello_world_main.c 如下
想引入luaxlib.h 的一些函数,然后运行lua脚本。

Code: Select all

#include <stdio.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "lauxlib.h"

void app_main(void)
{
    lua_State *L = luaL_newstate(); /* create state */
    // luaL_dofile(L,"");

    lua_close(L);

    printf("Hello world!\n");

    /* Print chip information */
    esp_chip_info_t chip_info;
    esp_chip_info(&chip_info);
    printf("This is %s chip with %d CPU cores, WiFi%s%s, ",
           CONFIG_IDF_TARGET,
           chip_info.cores,
           (chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
           (chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");

    printf("silicon revision %d, ", chip_info.revision);

    printf("%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024),
           (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");

    printf("Free heap: %d\n", esp_get_free_heap_size());

    for (int i = 10; i >= 0; i--)
    {
        printf("Restarting in %d seconds...\n", i);
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }

    printf("Restarting now.\n");
    fflush(stdout);
    esp_restart();
}
想问一下问题出在什么地方。
:D 任何线索都感激不尽。

Who is online

Users browsing this forum: Bing [Bot] and 118 guests