gpt4 book ai didi

luajit2.0.0 -- 段错误 : 11

转载 作者:行者123 更新时间:2023-12-02 05:19:04 26 4
gpt4 key购买 nike

我使用 http://lua-users.org/wiki/SimpleLuaApiExample 中的一个简单示例进行测试。该示例可以成功静态链接libluajit.a,但运行时出现以下错误消息:

Segmentation fault: 11

我使用的是2012年11月8日发布的LuaJIT-2.0.0。我的操作系统是 Mac OSX Lion 10.7.5。

$ uname -a
Darwin macmatoMacBook-Pro.local 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64

测试步骤:

编译luajit-2.0.0

$ cd lj2
$ ls
COPYRIGHT Makefile README doc dynasm etc src
$ make
==== Building LuaJIT 2.0.0 ====
make -C src
DYNLINK libluajit.so
LINK luajit
OK Successfully built LuaJIT
==== Successfully built LuaJIT 2.0.0 ====
$ rm src/*.so # force to use the static version: libluajit.a
$ cd ..

编译并运行示例应用

test.cscript.lua都来自 here 。文件夹lj2包含上面luajit-2.0.0的源码,刚刚编译成功。

$ ls
lj2 script.lua test.c
使用 clang 编译器
$ clang -o test test.c -I./lj2/src -L./lj2/src -lluajit
$ ./test
Segmentation fault: 11
使用gcc编译器
$ gcc -o test test.c -I./lj2/src -L./lj2/src -lluajit
$ ./test
Segmentation fault: 11
<小时/>

但是如果我用 test.c 替换 lj2/src/luajit.c ,它会给我成功。这很奇怪。见下文:

$ cd lj2
$ make clean
$ mv src/luajit.c src/luajit.c.orig
$ cp ../test.c src/luajit.c
$ make
$ cp src/luajit ../
$ cd ..
$ ./luajit
The table the script received has:
1 2
2 4
3 6
4 8
5 10
Returning data back to C
Script returned: 30

最佳答案

问题已解决。本页有一节解释了如何嵌入 LuaJIT:
http://luajit.org/install.html

  • If you're building a 64 bit application on OSX which links directly or indirectly against > LuaJIT, you need to link your main executable with these flags:

    -pagezero_size 10000 -image_base 100000000

Also, it's recommended to rebase all (self-compiled) shared libraries which are loaded at runtime on OSX/x64 (e.g. C extension modules for Lua). See: man rebase

现在,让我再测试一下:

$ clang -o test test.c -O3 -I./lj2/src -L./lj2/src -lluajit -pagezero_size 10000 -image_base 100000000
$ ./test
The table the script received has:
1 2
2 4
3 6
4 8
5 10
Returning data back to C
Script returned: 30

valgrind 返回

$ valgrind ./test
bad executable (__PAGEZERO is not 4 GB)
valgrind: ./test: cannot execute binary file

这是另一个问题。

关于luajit2.0.0 -- 段错误 : 11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13359821/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com