Search code examples
c++opensslundefined-symbol

OpenSSL 1.0.0-FIPS Symbol Lookup Error


I wrote a C++ SSL Socket class that uses the OpenSSL API. The version of OpenSSL I am using is "OpenSSL 1.0.0-fips" if that matters. This class belongs to a shared library that I have written.

I am trying to write a bare bones unit test of my class and I cannot get the SSL_CTX structure to allocate.

Here is my header file:

#ifndef __TDLS_SSL_SOCKET_HPP__
#define __TDLS_SSL_SOCKET_HPP__

#include <stdexcept>

#include <openssl/ssl.h>
#include <openssl/x509v3.h>
#include <openssl/err.h>

class TdlsSSLSocket
{
public:
  TdlsSSLSocket(const SSL_METHOD* method);
protected:
  SSL_CTX* ctx;
};

#endif

Here is the implementation of the constructor:

#include "TdlsSSLSocket.hpp"

TdlsSSLSocket::TdlsSSLSocket(const SSL_METHOD* method)
{
  ctx = SSL_CTX_new(method);
  if(!ctx)
  {
    throw std::runtime_error("Failed to initialize SSL CTX object");
  }
}

Here is how I compile this source code:

g++  -fPIC -g -O2 -Wall  -c -o TdlsSSLSocket.o TdlsSSLSocket.cpp
ld -r TdlsTCPSocket.o TdlsTCPClient.o TdlsTCPServer.o ReferenceCounter.o TdlsSSLSocket.o -o socket.o

Here is how I create the shared library:

g++ -shared -Wl,-soname,libttshared.so.2 -lssl -o libttshared.so.2.0 logger/log.o conf/conf_objs.o seq/seq.o socket/socket.o

Here is my C++ unit test where I attempt to exercise the class.

#include <iostream>

#include "TdlsSSLSocket.hpp"

using namespace std;

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

  SSL_library_init();
  SSL_load_error_strings();

  TdlsSSLSocket ssl_server(TLSv1_method());

}

And I build it like so:

g++ -o TestSSLServer TestSSLServer.o ../../libttshared.so -L../.. -lttshared

And when I execute the unit test, I get the following error:

[tlytle@vraptor3 test]$ TestSSLServer
TestSSLServer: symbol lookup error: TestSSLServer: undefined symbol: _ZN13TdlsSSLSocketC1EPK13ssl_method_st

The strange undefined symbol _ZN13TdlsSSLSocketC1EPK13ssl_method_st almost looks like C++ name mangling could be the culprit. But, I tried wrapping the class in extern "C" but I got the same error.

Any suggestions?


Solution

  • For anyone who reads this, the problem was not the OpenSSL library. The undefined symbol problem means that the linker could not resolve the given symbol. I performed a ldd on the unit test binary TestSSLServer and it revealed that I was not linking to the current version of libttshared.so. I set my LD_LIBRARY_PATH variable to include the directory of the new shared library and the program executed successfully.