我使用http://lua-users.org/wiki/SimpleLuaApiExample中的一个简单示例来进行测试。该示例可以静态地链接到liblajit.a以获得成功,但是在运行它时会出现此错误消息:
Segmentation fault: 11我使用LuaJIT-2.0.0在2012-11-08年发布。我的操作系统是MacOSXLion10.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.c和script.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 2/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 发布于 2012-11-13 12:39:14
问题解决了。有一节解释了如何在此页面中嵌入LuaJIT:
http://luajit.org/install.html
此外,建议将所有在运行时加载到OSX/x64 (例如用于Lua的C扩展模块)的共享库(自编译)重新建立在基础上。见:人的重新基地
现在,让我再试一次:
$ 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 ./test
bad executable (__PAGEZERO is not 4 GB)
valgrind: ./test: cannot execute binary file这是另一个问题。
https://stackoverflow.com/questions/13359821
复制相似问题