听到mruby的消息激励我开始学习C编程。我已经在网上学习了一些教程,所以我了解基本知识,但是现在我想通过编译一个示例应用程序来开始使用mruby。我知道如何编译一个C文件,但我一直在努力找出如何同时编译mruby和我自己的代码。我在macosx10.8上使用GCC。使用此示例:#include <stdlib.h>#include <stdio.h>#include <mruby.h>#include <mruby/compile.h>int main(void){ mrb_state *mrb = mrb_open(); char code[] = "p 'hello world!'"; printf("Executing Ruby code from C!\n"); mrb_load_string(mrb, code); return 0;}并运行此命令:gcc example.c很明显我错了:engine.c:4:19: error: mruby.h: No such file or directory我已经克隆了git repo并创建了一个指向include目录的符号链接,但我确信我做得不对。我应该如何在代码中包含mruby以便将其全部编译在一起?更新:这是我所拥有的目录结构,请注意指向mruby include目录的符号链接:$ tree -l ..├── example.c└── include └── mruby -> ../../mruby/include ├── mrbconf.h ├── mruby │   ├── array.h │   ├── class.h │   ├── compile.h │   ├── data.h │   ├── debug.h │   ├── dump.h │   ├── gc.h │   ├── hash.h │   ├── irep.h │   ├── khash.h │   ├── numeric.h │   ├── proc.h │   ├── range.h │   ├── string.h │   ├── value.h │   └── variable.h └── mruby.h当我通过包含目录进行编译时:gcc example.c -I include/mruby我得到以下错误:Undefined symbols for architecture x86_64: "_mrb_load_string", referenced from: _main in ccd8XYkm.o "_mrb_open", referenced from: _main in ccd8XYkm.old: symbol(s) not found for architecture x86_64collect2: ld returned 1 exit status更新:我遵循了mruby/INSTALL文件中的说明(基本上就是说在mruby项目的根目录中运行make)。这在mruby/build/host目录中添加了一组目录和字段,包括文件lib/libmruby.a。我能够在编译时包含这个文件来编译示例脚本。gcc -Iinclude/mruby example.c ../mruby/build/host/lib/libmruby.a现在我运行我的应用程序:$ ./a.outExecuting Ruby code from C!"hello world!" 最佳答案 而不是#include <mruby.h>#include <mruby/compile.h>尝试#include "mruby.h"#include "mruby/compile.h"如果有什么不同,请告诉我。编译器使用不同的搜索路径搜索includes with和“”。“”是本地的。你也可以试试gcc -Ipath/to/ruby/include/dir example.c
09-28 09:16