Results 1 to 6 of 6

Thread: Compilation error: "collect2: ld returned 1 exit status" when ussing QSslKey

  1. #1
    Join Date
    Dec 2010
    Posts
    7
    Thanks
    1
    Platforms
    Windows

    Default Compilation error: "collect2: ld returned 1 exit status" when ussing QSslKey

    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:

    Qt Code:
    1. QFile file(PRIVATEKEY_FILE);
    2.  
    3. file.open(QIODevice::ReadOnly);
    4. if (!file.isOpen()) {
    5. qWarning("No se puede abrir %s", PRIVATEKEY_FILE);
    6. return;
    7. }
    8.  
    9. QSslKey key(&file, QSsl::Rsa, QSsl::Der, QSsl::PrivateKey, "a012345679");
    10.  
    11. if (key.isNull()) {
    12. qWarning("No se pudo obtener la llave privada");
    13. return;
    14. }
    To copy to clipboard, switch view to plain text mode 

    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'
    Last edited by wysota; 14th December 2010 at 00:51. Reason: missing [code] tags

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Compilation error: "collect2: ld returned 1 exit status" when ussing QSslKey

    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.

  3. The following user says thank you to squidge for this useful post:

    Pechugo66 (14th December 2010)

  4. #3
    Join Date
    Dec 2010
    Posts
    7
    Thanks
    1
    Platforms
    Windows

    Default Re: Compilation error: "collect2: ld returned 1 exit status" when ussing QSslKey

    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'

  5. #4
    Join Date
    Dec 2010
    Posts
    7
    Thanks
    1
    Platforms
    Windows

    Default Re: Compilation error: "collect2: ld returned 1 exit status" when ussing QSslKey

    Problem solved, I added libQtNetwor4.a

  6. #5
    Join Date
    Dec 2010
    Posts
    11
    Thanks
    1

    Default Re: Compilation error: "collect2: ld returned 1 exit status" when ussing QSslKey

    The had the same error. Here is my case from my blog http://kdelchev.com/articles/other/Q...it_status.html

  7. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Compilation error: "collect2: ld returned 1 exit status" when ussing QSslKey

    This should be handled for you by adding "network" to the QT variable in your PRO file:
    Qt Code:
    1. QT += network
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Collect2:Id Returned 1 exit status
    By c_srikanth1984 in forum Qt Programming
    Replies: 9
    Last Post: 14th February 2010, 05:58
  2. error: collect2: ld returned 1 exit status
    By srohit24 in forum Qt Programming
    Replies: 3
    Last Post: 1st December 2009, 07:32
  3. error: collect2: ld returned 1 exit status
    By nataly in forum Qt Programming
    Replies: 4
    Last Post: 13th October 2009, 14:39
  4. collect2: ld returned 1 exit status error
    By gmsk19 in forum Qt Tools
    Replies: 11
    Last Post: 25th July 2009, 03:05
  5. collect2: ld returned 1 exit status
    By assismvla in forum Qt Programming
    Replies: 1
    Last Post: 25th May 2009, 02:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.