c++ - libshout 构建对 SSL_is_init_finished 的 undefined reference

标签 c++ ssl gcc openssl cygwin

我目前正在尝试使用 libshout 构建一个简单的 IceCast 供应商。

很遗憾,我无法解决一些链接器错误:

Invoking: Cygwin C++ Linker
g++ -L"D:\Programme\Cygwin\usr\x86_64-w64-mingw32\sys-root\mingw\include\ogg" -L"D:\Programme\Cygwin\usr\x86_64-w64-mingw32\sys-root\mingw\include" -L"D:\Programme\Cygwin\usr\x86_64-w64-mingw32\sys-root\mingw\include\vorbis" -o "LibshoutJavaAdapter.exe"  ./src/LibshoutJavaAdapter.o   -lshout -lvorbis -logg -lssl -lcrypto
/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../lib/libshout.a(tls.o): In function `tls_setup_process':
/cygdrive/d/Programme/utility/libshout-2.4.1/src/tls.c:200: undefined reference to `SSL_is_init_finished'
/cygdrive/d/Programme/utility/libshout-2.4.1/src/tls.c:200:(.text+0x74): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SSL_is_init_finished'
/cygdrive/d/Programme/utility/libshout-2.4.1/src/tls.c:203: undefined reference to `SSL_is_init_finished'
/cygdrive/d/Programme/utility/libshout-2.4.1/src/tls.c:203:(.text+0x8f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SSL_is_init_finished'
/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../lib/libshout.a(tls.o): In function `tls_setup':
/cygdrive/d/Programme/utility/libshout-2.4.1/src/tls.c:66: undefined reference to `OPENSSL_init_ssl'
/cygdrive/d/Programme/utility/libshout-2.4.1/src/tls.c:66:(.text+0x4ad): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `OPENSSL_init_ssl'
/cygdrive/d/Programme/utility/libshout-2.4.1/src/tls.c:67: undefined reference to `OPENSSL_init_ssl'
/cygdrive/d/Programme/utility/libshout-2.4.1/src/tls.c:67:(.text+0x4b9): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `OPENSSL_init_ssl'
/cygdrive/d/Programme/utility/libshout-2.4.1/src/tls.c:68: undefined reference to `SSLeay_add_all_algorithms'
/cygdrive/d/Programme/utility/libshout-2.4.1/src/tls.c:68:(.text+0x4be): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SSLeay_add_all_algorithms'
/cygdrive/d/Programme/utility/libshout-2.4.1/src/tls.c:69: undefined reference to `OPENSSL_init_ssl'
/cygdrive/d/Programme/utility/libshout-2.4.1/src/tls.c:69:(.text+0x4c7): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `OPENSSL_init_ssl'
collect2: error: ld returned 1 exit status

我使用的是 CygWin 的 GCC 64 位版本,但如果需要,还可以使用 32 位版本进行编译。 使用 make 触发构建

到目前为止,我的实际代码非常基础(我才刚刚开始使用这个库)

#include <iostream>
#include <shout/shout.h>

int main() {
    shout_init();
    std::cout << "!!!Hello World!!!" << std::endl; // prints !!!Hello World!!!
    return 0;
}

我在这个 Order(-l) 中使用以下库作为链接器: shout -> 我尝试使用的实际库 vorbis 奥格 SSL 加密

从错误的外观来看,我认为这与 ssl 有某种关系,但我确实包括了那些,不是吗? 我已经尝试轮换顺序,但这只会产生更多错误,所以我认为顺序是正确的...

编辑 1:

正如 nnovich-OK 所建议的,我像这样更改了我的代码以检查 OpenSSL:

#include <iostream>
//#include <shout/shout.h>
#include <ctype.h>
#include <openssl/ssl.h>

int main() {
    //shout_init();
    OPENSSL_init();
    OPENSSL_INIT_SETTINGS * test = NULL;
    OPENSSL_init_ssl(0,test);
    //SSL_is_init_finished();
    std::cout << "!!!Hello World!!!" << std::endl; // prints !!!Hello World!!!
    return 0;
}

导致的链接错误如下所示:

g++ -L"D:\Programme\Cygwin\usr\x86_64-w64-mingw32\sys-root\mingw\include\ogg" -L"D:\Programme\Cygwin\usr\x86_64-w64-mingw32\sys-root\mingw\include" -L"D:\Programme\Cygwin\usr\x86_64-w64-mingw32\sys-root\mingw\include\vorbis" -o "LibshoutJavaAdapter.exe"  ./src/LibshoutJavaAdapter.o   -lshout -lvorbis -logg -lssl -lcrypto
./src/LibshoutJavaAdapter.o: In function `main':
/cygdrive/d/Install und andere Sachen/Eclipse/C++/LibshoutJavaAdapter/Debug/../src/LibshoutJavaAdapter.cpp:18: undefined reference to `OPENSSL_init_ssl'
/cygdrive/d/Install und andere Sachen/Eclipse/C++/LibshoutJavaAdapter/Debug/../src/LibshoutJavaAdapter.cpp:18:(.text+0x27): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `OPENSSL_init_ssl'
collect2: error: ld returned 1 exit status

我看到 ssl.h 中的 OPENSSL_init_ssl 有问题,但 crypto.h 中的 OPENSSL_init 没有问题(女巫实习生包含在 ssl.h 中)

这会给任何人任何想法吗?

解决此问题的任何提示表示赞赏

最佳答案

我没有相同的设置可以尝试,但提供的信息似乎足够清楚。 Linker 无法从 ssl 库中找到函数,因此您需要专注于链接 ssl。我认为,问题场景可以简化为调用 OPENSSL_init_ssl() 的简单主函数(参数无关紧要,因为您不会执行它)和仅涉及链接 openssl 的构建过程。解决此链接失败将有助于解决您当前的案例。因此,让 Google 和 SO 与您同在:)

PS 我宁愿将所有这些都放在评论中,但不允许新人这样做。

编辑:

随后的故障排除(查看下面的评论)揭示了真正的根本原因。系统有几个 libssl 实例(例如,一些应用程序安装带来了另一个版本)和链接器使用的实例不适合当前构建(例如,构建 64 位应用程序时使用 32 位版本)。因此解决方案是将链接器置于详细模式并检查库路径是否符合预期。

关于c++ - libshout 构建对 SSL_is_init_finished 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41300617/

相关文章:

c++ - 在圆圈周围放置一个 ofImage

c++ - 列出 push_back 一个包含字符串类型核心的结构

wordpress - 我已经在 wordpress 网站上安装了 SSL 证书,但是安装 ssl 图像后没有显示( Logo 图像等)

Java SSL 套接字无法从客户端连接

ssl - 进行身份验证时如何在jetty服务器中获取客户端证书

gcc - 内联汇编错误,阻止 gcc 编译尝试

c++ - 使用 MinGW 编译 SFML 项目

c++ - 在链表中遍历后如何获得列表的头部?

c++ - 如何从 "this"指针知道 gcc 的 c++ 对象的 RTTI 信息?

c - GCC fastcall 函数定义