PDA

View Full Version : Compilation error: "collect2: ld returned 1 exit status" when ussing QSslKey



Pechugo66
13th December 2010, 23:08
I'm ussing QSslKey to obtain Private Key of a .key file, but when compiling, I'm getting the above error. The problem is with the QSslKey instruction.

Where is part of my code:


QFile file(PRIVATEKEY_FILE);

file.open(QIODevice::ReadOnly);
if (!file.isOpen()) {
qWarning("No se puede abrir %s", PRIVATEKEY_FILE);
return;
}

QSslKey key(&file, QSsl::Rsa, QSsl::Der, QSsl::PrivateKey, "a012345679");

if (key.isNull()) {
qWarning("No se pudo obtener la llave privada");
return;
}


Here is the compile output:

Running build steps for project MD5...
Configuration unchanged, skipping qmake step.
Starting: "C:/Qt/2010.05/mingw/bin/mingw32-make.exe" -w
mingw32-make: Entering directory `C:/Programas C++ Builder/QT_eFact/eFact/MD5-build-desktop'

C:/Qt/2010.05/mingw/bin/mingw32-make -f Makefile.Debug

mingw32-make[1]: Entering directory `C:/Programas C++ Builder/QT_eFact/eFact/MD5-build-desktop'

g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\..\Qt\2010.05\qt\include\QtCore" -I"..\..\..\..\Qt\2010.05\qt\include\QtGui" -I"..\..\..\..\Qt\2010.05\qt\include" -I"..\..\..\..\OpenSSL-Win32\include" -I"..\..\..\..\Qt\2010.05\qt\include\QtNetwork" -I"..\..\..\..\Qt\2010.05\qt\include\ActiveQt" -I"debug" -I"." -I"..\MD5" -I"." -I"..\..\..\..\Qt\2010.05\qt\mkspecs\win32-g++" -o debug\mainwindow.o ..\MD5\mainwindow.cpp

g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\MD5.exe debug/main.o debug/mainwindow.o debug/moc_mainwindow.o -L"c:\Qt\2010.05\qt\lib" -lmingw32 -lqtmaind C:/OpenSSL-Win32/lib/libeay32.lib C:/OpenSSL-Win32/lib/ssleay32.lib -lQtGuid4 -lQtCored4

mingw32-make[1]: Leaving directory `C:/Programas C++ Builder/QT_eFact/eFact/MD5-build-desktop'

mingw32-make: Leaving directory `C:/Programas C++ Builder/QT_eFact/eFact/MD5-build-desktop'

debug/mainwindow.o:C:\Programas C++ Builder\QT_eFact\eFact\MD5-build-desktop/../MD5/mainwindow.cpp:188: undefined reference to `_imp___ZN7QSslKeyC1EP9QIODeviceN4QSsl12KeyAlgorit hmENS2_14EncodingFormatENS2_7KeyTypeERK10QByteArra y'

debug/mainwindow.o:C:\Programas C++ Builder\QT_eFact\eFact\MD5-build-desktop/../MD5/mainwindow.cpp:190: undefined reference to `_imp___ZNK7QSslKey6isNullEv'

debug/mainwindow.o:C:\Programas C++ Builder\QT_eFact\eFact\MD5-build-desktop/../MD5/mainwindow.cpp:193: undefined reference to `_imp___ZN7QSslKeyD1Ev'

debug/mainwindow.o:C:\Programas C++ Builder\QT_eFact\eFact\MD5-build-desktop/../MD5/mainwindow.cpp:193: undefined reference to `_imp___ZN7QSslKeyD1Ev'

collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\MD5.exe] Error 1

mingw32-make: *** [debug] Error 2

The process "C:/Qt/2010.05/mingw/bin/mingw32-make.exe" exited with code %2.
Error while building project MD5 (target: Desktop)
When executing build step 'Make'

squidge
13th December 2010, 23:22
My guess is that the functions in libeay32.lib and ssleay32.lib are C-style functions and you are trying to access them as C++ functions, hence the name mangling, so force the external definitions to be extern "C" to fix it.

Pechugo66
14th December 2010, 03:18
Thanks for your input. I have been programming C++ for quite some time and never had to combine with C code, so I really don't know where to start regarding the name mangling, besides I don't want to touch OpenSSL code, what I did, and base on your comments about the libeay32.lib and ssleay32.lib was to issolate the call to the QSslKey class and get rid of those libraries, so it would be just C++ code. But I'm getting the same results. Here is the compile output.

Running build steps for project Tst_QSslKey...
Configuration unchanged, skipping qmake step.
Starting: "C:/Qt/2010.05/mingw/bin/mingw32-make.exe" -w
mingw32-make: Entering directory `C:/Programas C++ Builder/QT_eFact/QSslKey/Tst_QSslKey-build-desktop'

C:/Qt/2010.05/mingw/bin/mingw32-make -f Makefile.Debug

mingw32-make[1]: Entering directory `C:/Programas C++ Builder/QT_eFact/QSslKey/Tst_QSslKey-build-desktop'

g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\..\Qt\2010.05\qt\include\QtCore" -I"..\..\..\..\Qt\2010.05\qt\include\QtGui" -I"..\..\..\..\Qt\2010.05\qt\include" -I"..\..\..\..\Qt\2010.05\qt\include\QtNetwork" -I"..\..\..\..\Qt\2010.05\qt\include\ActiveQt" -I"debug" -I"." -I"..\Tst_QSslKey" -I"." -I"..\..\..\..\Qt\2010.05\qt\mkspecs\win32-g++" -o debug\mainwindow.o ..\Tst_QSslKey\mainwindow.cpp

C:\Qt\2010.05\qt\bin\moc.exe -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\..\Qt\2010.05\qt\include\QtCore" -I"..\..\..\..\Qt\2010.05\qt\include\QtGui" -I"..\..\..\..\Qt\2010.05\qt\include" -I"..\..\..\..\Qt\2010.05\qt\include\QtNetwork" -I"..\..\..\..\Qt\2010.05\qt\include\ActiveQt" -I"debug" -I"." -I"..\Tst_QSslKey" -I"." -I"..\..\..\..\Qt\2010.05\qt\mkspecs\win32-g++" -D__GNUC__ -DWIN32 ..\Tst_QSslKey\mainwindow.h -o debug\moc_mainwindow.cpp

g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\..\Qt\2010.05\qt\include\QtCore" -I"..\..\..\..\Qt\2010.05\qt\include\QtGui" -I"..\..\..\..\Qt\2010.05\qt\include" -I"..\..\..\..\Qt\2010.05\qt\include\QtNetwork" -I"..\..\..\..\Qt\2010.05\qt\include\ActiveQt" -I"debug" -I"." -I"..\Tst_QSslKey" -I"." -I"..\..\..\..\Qt\2010.05\qt\mkspecs\win32-g++" -o debug\moc_mainwindow.o debug\moc_mainwindow.cpp

g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\Tst_QSslKey.exe debug/main.o debug/mainwindow.o debug/moc_mainwindow.o -L"c:\Qt\2010.05\qt\lib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4

debug/mainwindow.o: In function `MainWindow':

C:\Programas C++ Builder\QT_eFact\QSslKey\Tst_QSslKey-build-desktop/../Tst_QSslKey/mainwindow.cpp:22: undefined reference to `_imp___ZN7QSslKeyC1EP9QIODeviceN4QSsl12KeyAlgorit hmENS2_14EncodingFormatENS2_7KeyTypeERK10QByteArra y'

C:\Programas C++ Builder\QT_eFact\QSslKey\Tst_QSslKey-build-desktop/../Tst_QSslKey/mainwindow.cpp:24: undefined reference to `_imp___ZNK7QSslKey6isNullEv'

C:\Programas C++ Builder\QT_eFact\QSslKey\Tst_QSslKey-build-desktop/../Tst_QSslKey/mainwindow.cpp:27: undefined reference to `_imp___ZN7QSslKeyD1Ev'

C:\Programas C++ Builder\QT_eFact\QSslKey\Tst_QSslKey-build-desktop/../Tst_QSslKey/mainwindow.cpp:27: undefined reference to `_imp___ZN7QSslKeyD1Ev'

C:\Programas C++ Builder\QT_eFact\QSslKey\Tst_QSslKey-build-desktop/../Tst_QSslKey/mainwindow.cpp:22: undefined reference to `_imp___ZN7QSslKeyC1EP9QIODeviceN4QSsl12KeyAlgorit hmENS2_14EncodingFormatENS2_7KeyTypeERK10QByteArra y'

C:\Programas C++ Builder\QT_eFact\QSslKey\Tst_QSslKey-build-desktop/../Tst_QSslKey/mainwindow.cpp:24: undefined reference to `_imp___ZNK7QSslKey6isNullEv'

C:\Programas C++ Builder\QT_eFact\QSslKey\Tst_QSslKey-build-desktop/../Tst_QSslKey/mainwindow.cpp:27: undefined reference to `_imp___ZN7QSslKeyD1Ev'

C:\Programas C++ Builder\QT_eFact\QSslKey\Tst_QSslKey-build-desktop/../Tst_QSslKey/mainwindow.cpp:27: undefined reference to `_imp___ZN7QSslKeyD1Ev'

collect2: ld returned 1 exit status

mingw32-make[1]: Leaving directory `C:/Programas C++ Builder/QT_eFact/QSslKey/Tst_QSslKey-build-desktop'

mingw32-make: Leaving directory `C:/Programas C++ Builder/QT_eFact/QSslKey/Tst_QSslKey-build-desktop'

mingw32-make[1]: *** [debug\Tst_QSslKey.exe] Error 1

mingw32-make: *** [debug] Error 2

The process "C:/Qt/2010.05/mingw/bin/mingw32-make.exe" exited with code %2.
Error while building project Tst_QSslKey (target: Desktop)
When executing build step 'Make'

Pechugo66
14th December 2010, 15:02
Problem solved, I added libQtNetwor4.a

kode
14th December 2010, 15:46
The had the same error. Here is my case from my blog http://kdelchev.com/articles/other/Qt_Error_collect2:_ld_returned_1_exit_status.html

ChrisW67
15th December 2010, 02:54
This should be handled for you by adding "network" to the QT variable in your PRO file:


QT += network