1

I´m trying to compile a very simple proyect in Qt with OpenSSL, but it always show me a linker error, however works fine when I compile in Visual C++ 2010.

Code:

#include <openssl\sha.h>

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

    unsigned char in[] = "Hola";
    unsigned char out[33] = {0};

    SHA256(in,4,out);
    return 0;
}

Error:

main.obj:-1: error: LNK2019: símbolo externo _SHA256 sin resolver al que se hace referencia en la función _main

I have installed:

  • Qt 5.1.1 for Windows 32-bit (VS 2010, 505 MB)
  • OpenSSL-Win32 from a binary file (Win32 OpenSSL v1.0.1e, 16MB)
  • Microsoft Visual C++ 2010 (Express Edidition)

The .pro file from Qt is:

#-------------------------------------------------
#
# Project created by QtCreator 2013-11-29T23:21:36
#
#-------------------------------------------------

QT       += core
QT       -= gui
TARGET = prueba_openssl
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += C:/OpenSSL-Win32/include
LIBS += -L"C:/OpenSSL-Win32/lib" -llibeay32

Any suggestions?

Thank you!

2 Answers2

0

Undefined reference means either library is not linked or found or library is linker but the function is not found.

In your case, it is looking for _SHA256 which means function is undecorated and is using C.

It seems that you forget to use extern "C". Either declare the required the function as follows:

extern "C"  unsigned char *SHA256(const unsigned char *d, size_t n,unsigned char *md);

Or put extern "C" under C++ macro. I hope this should solve your purpose.

doptimusprime
  • 9,115
  • 6
  • 52
  • 90
0

Using extern "C" did not resolve the problem.

I found a solution writing in Additional arguments : "LIBS+=-LC:/OpenSSL-Win32/lib -llibeay32" "INCLUDE += C:/OpenSSL-Win32/include" "LIBPATH+=C:/OpenSSL-Win32/lib". (from Build Steps for your active project).

For some reason, the configuration of the .pro file is being ignored and has no effect on the project.

Thank you!