在 C++ 程序中嵌入 ruby 源时出错

Error on embedding ruby source on c++ program

我在 C++ 方面还不是很有经验,但我正在尝试将 ruby 1.8 嵌入到 qt 应用程序中,我所做的只是下载 ruby源代码并将其放在名为“3rdparty”和 运行 ./configure 的项目子文件夹中,在该文件夹内和 make 之后,现在我收到以下错误:

:-1: error: /home/gabriel/dev/ruby-exps/embed-ruby-first-tries/3rdparty/ruby-1.8.7-p374//libruby-static.a(dln.o): undefined reference to symbol 'dlclose@@GLIBC_2.2.5'

/lib/x86_64-linux-gnu/libdl.so.2:-1: error: error adding symbols: DSO missing from command line

:-1: error: collect2: error: ld returned 1 exit status

我的.pro文件是这样的:

QT += core
QT -= gui

CONFIG += c++11

TARGET = embed-ruby-first-tries
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app

SOURCES += main.cpp

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/3rdparty/ruby-1.8.7-p374/release/ -lruby-static
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/3rdparty/ruby-1.8.7-p374/debug/ -lruby-static
else:unix: LIBS += -L$$PWD/3rdparty/ruby-1.8.7-p374/ -lruby-static

INCLUDEPATH += 3rdparty/ruby-1.8.7-p374
DEPENDPATH += 3rdparty/ruby-1.8.7-p374

win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/3rdparty/ruby-1.8.7-p374/release/libruby-static.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/3rdparty/ruby-1.8.7-p374/debug/libruby-static.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/3rdparty/ruby-1.8.7-p374/release/ruby-static.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/3rdparty/ruby-1.8.7-p374/debug/ruby-static.lib
else:unix: PRE_TARGETDEPS += $$PWD/3rdparty/ruby-1.8.7-p374/libruby-static.a

我的 main.cpp 文件是这样的:

#include <QDebug>
#include <ruby.h>


int main(int argc, char *argv[])
{
   ruby_init();

   return ruby_cleanup(0);
}

我正在使用 qt 5.6 和 ruby 1.8.7-p374 源代码,如果有人告诉我如何将 ruby 嵌入 cpp 程序或在至少帮助我了解发生了什么。

DSO missing from command line

这通常表示您在链接阶段缺少某些库。虽然错误消息不是很详细。

在这种情况下,undefined reference to symbol 'dlclose' 给出了缺少哪个库的提示。在这种情况下 dlclose 恰好在 libdl 中。所以添加:

-ldl

...链接器选项 (LIBS +=) 应该能让您更接近解决方案。