【问题标题】:Error on embedding ruby source on c++ program在 C++ 程序中嵌入 ruby​​ 源时出错
【发布时间】:2017-03-15 12:47:29
【问题描述】:

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

:-1: 错误: /home/gabriel/dev/ruby-exps/embed-ruby-first-tries/3rdparty/ruby-1.8.7-p374//libruby-static.a(dln.o):对符号'dlclose@@GLIBC_2.2.5'的未定义引用

/lib/x86_64-linux-gnu/libdl.so.2:-1:错误:添加符号时出错:DSO 命令行缺失

:-1: error: collect2: error: ld 返回 1 个退出状态

我的 .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 程序或至少帮助我了解发生了什么,那就太好了。

【问题讨论】:

  • -ldl 添加到链接器参数?
  • @Casper 你的意思是在 .pro 文件上添加一行 LIBS += -ldl 吗?我不确定是否是这样,但我做到了,现在它开始返回此错误:
    /home/gabriel/dev/ruby-exps/embed-ruby-first-tries/3rdparty/ruby -1.8.7-p374/string.c:4513:错误:未定义对“crypt”的引用
    :-1:错误:collect2:错误:ld返回1退出状态
  • 我用LIBS += -lcrypt 解决了,谢谢你,它终于可以工作了,你应该把它作为答案发布,这样我就可以将它标记为已解决

标签: c++ ruby qt embedded-ruby


【解决方案1】:

命令行中缺少 DSO

这通常表明您在链接阶段缺少某些库。不过,错误消息的描述性不是很好。

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

-ldl

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-29
    • 1970-01-01
    • 2014-05-04
    • 1970-01-01
    • 2010-09-19
    • 2014-05-21
    • 1970-01-01
    相关资源
    最近更新 更多