0

I'm currently trying to build a simple IceCast supplier using libshout.

Unfortunately, I am unable to resolve some linker errors:

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

I'm using CygWin's GCC 64 bit version, butalso got a 32 version to compile with if needed. The build is triggered using make

My actual code up to now is pretty basic (I'm only just getting started with this library)

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

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

I use the following libraries for the linker in this Order(-l): shout -> the actual library i try to use vorbis ogg ssl crypto

From the look of the error I suppose, that this is related to ssl somehow, but i did include those didn't I ? I already tried rotating the order, but that only created more errors, so I suppose the order is correct ...

Edit 1:

As nnovich-OK suggested, I altered my code like this to check 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;
}

There resulting Linking error looks like this:

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

I see that there is a problem with OPENSSL_init_ssl from ssl.h but not with OPENSSL_init from crypto.h (witch intern is included by ssl.h)

Does that gives anyone any idea?

Any hints to resolving this Problem appreciated

Omega1001
  • 502
  • 6
  • 14
  • 1
    The Cygwin system version of OpenSSL is 1.0.2j (at the time of this writing). `SSL_is_init_finished` is part of OpenSSL 1.1.0. I don't see a compile command indicating you are using the 1.1.0 version. At minimum, I would expect to see something like `-I "D:\Programme\OpenSSL-1.1.0\include"`. Your link command should include something like `-L "D:\Programme\OpenSSL-1.1.0\lib"`. – jww Dec 25 '16 at 13:13

1 Answers1

1

I don't have the same setup to try, but provided info seems clear enough. Linker can't find functions from ssl library, so you need to focus on linking ssl. I think, issue scenario can be reduced to simple main function calling OPENSSL_init_ssl() (parameters doesn't matter, since you aren't going to execute it) and build process involving linking only openssl. Resolving this linking failure will help to resolve your current case. So let the Google and SO be with you :)

PS I'd rather put all this into comment, but SO newcomers aren't allowed to.

Edit:

Subsequent troubleshooting (check comments below) revealed actual root cause. System has several libssl instances (e.g. some app installation brought another version) and linker used instance not suitable for current build (e.g. 32bit version in building 64bit app). So the solution was to put linker into verbose mode and to check whether library paths are as expected.

nnovich-OK
  • 2,900
  • 2
  • 13
  • 16
  • Hi, doing as you suggested produced the exact same error as I experienced before (Well one of it anyway). Do you have any Idea how I could try to resolve this or at least get a better view about what is going wrong? – Omega1001 Dec 24 '16 at 21:47
  • Well, linker doesn't say "can't find -lssl", so it can locate lib, but can't get necessary symbols. The first thing I would check is whether libssl intended for the same platform as main.o produced by compiler. It's possible, that compiler targets x64 by default, while openssl is intended for 32-bit or vise versa. Check [here](http://stackoverflow.com/questions/9260948/how-to-see-the-compilation-platform-of-a-static-library-file) and maybe [here](http://stackoverflow.com/questions/8659694/how-can-i-tell-whether-my-gcc-is-compiling-64bit-by-default) – nnovich-OK Dec 25 '16 at 07:42
  • Couple more things to mention: – nnovich-OK Dec 25 '16 at 11:44
  • a) I run into [this topic](https://forum.nginx.org/read.php?29,265783,265783) describing changes in openssl initialization. It looks like OPENSSL_init_ssl() isn't in old releases. Make sure your openssl is up to date. I would suggest direct check, that library libssl contains this function within list of symbols [look at most liked answer here](http://stackoverflow.com/questions/5108079/how-do-i-find-out-which-functions-of-a-shared-object-are-used-by-a-program-or-an) – nnovich-OK Dec 25 '16 at 11:51
  • 1
    b) make sure, ld is linking right library from right path. I had experience with small personal app depending on SDL lib intended for Windows x64. I put necessary SDL libs to my system, but linker located SDL lib for 32bit platform, which was previously brought by some steam game, and building failed. I suggest putting linker in verbose mode, so full library paths are printed, and check if lib path is as expected. Quick googling (points here)[https://groups.google.com/forum/#!topic/gnu.gcc.help/4opcAQF6wyo] – nnovich-OK Dec 25 '16 at 12:03
  • Thank you for your effort. Suggestion b) actually brought the solution. Please edit your answer so it reflects the solution. – Omega1001 Dec 25 '16 at 13:17