构建包括Luajit的静态Linux二进制(带有Musl-Libc)的错误

发布于 2025-01-29 05:01:43 字数 1559 浏览 2 评论 0原文

我已经将Luajit Git Repo克隆并使用:

make STATIC_CC="musl-gcc" BUILDMODE="static"

然后,我将一个简单的LUA“ Hello World”脚本编译到C标头文件中:

luajit -b test.lua test.h

test.h:

#define luaJIT_BC_test_SIZE 52
static const unsigned char luaJIT_BC_test[] = {
27,76,74,2,10,45,2,0,3,0,2,0,4,54,0,0,0,39,2,1,0,66,0,2,1,75,0,1,0,20,72,101,
108,108,111,32,102,114,111,109,32,76,117,97,33,10,112,114,105,110,116,0
};

之后,我通过遵循官方示例写了一个简单的C包装器, test.c:

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

#include "test.h"

int main(void) {
    int error;
    lua_State *L = lua_open();
    luaL_openlibs(L);
    
    error = luaL_loadbuffer(L, (const char *) luaJIT_BC_test, luaJIT_BC_test_SIZE, "test") || lua_pcall(L, 0, 0, 0);
    if (error) {
        fprintf(stderr, "%s", lua_tostring(L, -1));
        lua_pop(L, 1);
    }
    
    lua_close(L);
    return 0;
}

但是,当我尝试构建它时,它会出现错误:

$ musl-gcc -static -ILuaJIT/src -LLuaJIT/src -o test test.c -lluajit
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/12.1.0/libgcc_eh.a(unwind-dw2-fde-dip.o): in function `_Unwind_Find_FDE':
(.text+0x1953): undefined reference to `_dl_find_object'
collect2: error: ld returned 1 exit status

它与libgcc有关,因此我尝试使用Musl-Clang构建所有内容,但仍然有相同的错误。有人可以解释我在这里缺少什么吗?

I've cloned the LuaJIT git repo and built it with:

make STATIC_CC="musl-gcc" BUILDMODE="static"

Then, I compiled a simple Lua "hello world" script into a C header file:

luajit -b test.lua test.h

test.h:

#define luaJIT_BC_test_SIZE 52
static const unsigned char luaJIT_BC_test[] = {
27,76,74,2,10,45,2,0,3,0,2,0,4,54,0,0,0,39,2,1,0,66,0,2,1,75,0,1,0,20,72,101,
108,108,111,32,102,114,111,109,32,76,117,97,33,10,112,114,105,110,116,0
};

After that, I wrote a simple C wrapper by following the official example, test.c:

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

#include "test.h"

int main(void) {
    int error;
    lua_State *L = lua_open();
    luaL_openlibs(L);
    
    error = luaL_loadbuffer(L, (const char *) luaJIT_BC_test, luaJIT_BC_test_SIZE, "test") || lua_pcall(L, 0, 0, 0);
    if (error) {
        fprintf(stderr, "%s", lua_tostring(L, -1));
        lua_pop(L, 1);
    }
    
    lua_close(L);
    return 0;
}

But when I try to build it, it crashes with an error:

$ musl-gcc -static -ILuaJIT/src -LLuaJIT/src -o test test.c -lluajit
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/12.1.0/libgcc_eh.a(unwind-dw2-fde-dip.o): in function `_Unwind_Find_FDE':
(.text+0x1953): undefined reference to `_dl_find_object'
collect2: error: ld returned 1 exit status

It's related to libgcc, so I tried building everything with musl-clang, but still got the same error. Can someone explain what I'm missing here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独岁月 2025-02-05 05:01:43

弄清楚了 - 我需要用target_xcflags = -dluajit_no_unwind构建luajit so:

make STATIC_CC="musl-gcc" BUILDMODE="static" TARGET_XCFLAGS=-DLUAJIT_NO_UNWIND

我想这只是禁用C ++例外支持,但我不确定真实含义是什么。目前似乎正常。

Figured it out - I needed to build LuaJIT with TARGET_XCFLAGS=-DLUAJIT_NO_UNWIND like so:

make STATIC_CC="musl-gcc" BUILDMODE="static" TARGET_XCFLAGS=-DLUAJIT_NO_UNWIND

I guess this just disables C++ exceptions support, but I'm not sure what the real implications are. Seems to work fine, for now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文