我正在尝试通过RubyInline(https://github.com/seattlerb/rubyinline)在Ruby中运行一些C代码。
代码
require 'inline'
class InlineTest
inline do |builder|
builder.add_compile_flags('-lsqlite3')
p builder.flags
builder.include '<stdio.h>'
builder.include '<sqlite3.h>'
builder.c '
void main(){
sqlite3 *db;
char *zErrMsg = 0;
int rc;
rc = sqlite3_open("test.db", &db);
if( rc ) {
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
return(0);
} else {
fprintf(stderr, "Opened database successfully\n");
}
sqlite3_close(db);
}'
end
end
InlineTest.new.main
输出
["-lsqlite3"]
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': /home/vbhv/.ruby_inline/ruby-2.3.0/Inline_InlineTest_fad58de7366495db4650cfefac2fcd61.so: undefined symbol: sqlite3_open - /home/vbhv/.ruby_inline/ruby-2.3.0/Inline_InlineTest_fad58de7366495db4650cfefac2fcd61.so (LoadError)
from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /var/lib/gems/2.3.0/gems/RubyInline-3.12.4/lib/inline.rb:523:in `load'
from /var/lib/gems/2.3.0/gems/RubyInline-3.12.4/lib/inline.rb:857:in `inline'
from main.rb:14:in `<class:InlineTest>'
from main.rb:13:in `<main>'
现在,当我将gcc与上述C代码一起使用时,'-lsqlite3'可以正常工作。 如您所见,add_compiler_flags运行正常。参见输出的第一行。但是在那之后我不知道出了什么问题。
谢谢。