Results 1 to 3 of 3

Thread: Linker errors when building DLL dependent on static lib(Crypto++)

  1. #1
    Join Date
    Dec 2014
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Linker errors when building DLL dependent on static lib(Crypto++)

    All

    Here is a preface - I have a C++ + Qt application, it consists of several projects and we are using MSVC 2012 to build it. Now, I'm implementing build scripts to start deploying build server. So, I started creating Qt .pro files for each and every project we have.

    **Now the problem** - we use Crypto++ library(http://www.cryptopp.com/) which we build from source code and the output is static lib, and we have DLL which depends on cryptlib.lib.

    I wrote .pro file for Cryptlib and I'm able to build it using qmake/jom

    Qt Code:
    1. QT -= core gui
    2. QMAKE_CFLAGS += /Zc:wchar_t
    3.  
    4. TEMPLATE = lib
    5. TARGET = cryptlib
    6.  
    7. Release:DESTDIR = ./Release
    8. Debug:DESTDIR = ./Debug
    9.  
    10. CONFIG += staticlib precompile_header
    11. DEFINES += _USING_V110_SDK71_ WINVER=0x0501 WIN32 _WINDOWS _MBCS
    12. DEFINES -= UNICODE
    13.  
    14. PRECOMPILED_HEADER = pch.h
    15. DEPENDPATH += .
    16.  
    17. include(CryptoPP.pri)@
    To copy to clipboard, switch view to plain text mode 

    I wrote .pro file for my DLL - it compiles fine, *but I'm getting linker errors on linkage phase*. The most interesting thing is that when I build cryptlib with MSVC2012 and *then* build DLL with qmake - then it link OK.

    What could be wrong? I checked all proj settings in MSVC projects and applied in my pro files. I checked names mangling in both libs built with MSVC and QT - mangled names look the same. Now I got stuck

    Qt Code:
    1. @# ----------------------------------------------------
    2. # This file is generated by the Qt Visual Studio Add-in.
    3. # ------------------------------------------------------
    4.  
    5. QT -= gui core
    6. QMAKE_CFLAGS += /Zc:wchar_t
    7.  
    8. TEMPLATE = lib
    9. TARGET = PSGLicensing
    10.  
    11. Release:DESTDIR = ./Release
    12. Debug:DESTDIR = ./Debug
    13.  
    14. CONFIG += dll
    15. DEFINES += _AFXDLL _USING_V110_SDK71_ WIN32 _WINDOWS _WINDLL _USRDLL DLL_LIBRARY PSGLICENSING_DLL_BUILD _MBCS _VC80_UPGRADE=0x0710
    16. DEFINES -= UNICODE
    17.  
    18. PRECOMPILED_HEADER = stdafx.h
    19. DEPENDPATH += .
    20.  
    21. win32:CONFIG(release, debug|release): LIBS += -L$$_PRO_FILE_PWD_/../CryptoPP/Release/ -lcryptlib
    22. else:win32:CONFIG(debug, debug|release): LIBS += -L$$_PRO_FILE_PWD_/../CryptoPP/Debug/ -lcryptlib
    23.  
    24. INCLUDEPATH += $$_PRO_FILE_PWD_/../CryptoPP/
    25. DEPENDPATH += $$_PRO_FILE_PWD_/../CryptoPP/
    26.  
    27. win32:CONFIG(release, debug|release): PRE_TARGETDEPS += $$_PRO_FILE_PWD_/../CryptoPP/Release/cryptlib.lib
    28. else:win32:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$_PRO_FILE_PWD_/../CryptoPP/Debug/cryptlib.lib
    29.  
    30. include(PSGLicensing.pri)@
    To copy to clipboard, switch view to plain text mode 


    In MSVC2012 we have following settings for

    **CryptLib**

    Qt Code:
    1. *Compiler:* /Yu"pch.h" /GS /GL /analyze- /W3 /Gy- /Zc:wchar_t /Zi /Gm- /O2 /Ob2 /Fd"Release\vc110.pdb" /fp:precise /Zp1 /D "_USING_V110_SDK71_" /D "NDEBUG" /D "_WINDOWS" /D "USE_PRECOMPILED_HEADERS" /D "WIN32" /D "WINVER=0x0501" /D "_VC80_UPGRADE=0x0710" /errorReport:prompt /GF- /WX- /Zc:forScope /arch:SSE /Gd /Oy /Oi /MD /Fa"Release\" /EHsc /nologo /Fo"Release\" /Fp"Release\cryptlib.pch"
    2.  
    3. *Linker:* /OUT:"SecretPath\CryptoPP\Release\cryptlib.lib" /LTCG /NOLOGO
    To copy to clipboard, switch view to plain text mode 

    and here are settings for **DLL**

    Qt Code:
    1. *Compiler*: /Yu"stdafx.h" /GS /analyze- /W3 /Zc:wchar_t /I"SecretPath\PSGLicensing\IncludeExp" /Zi /Gm- /O2 /Fd"Release\vc110.pdb" /fp:precise /D "_USING_V110_SDK71_" /D "WIN32" /D "_WINDOWS" /D "NDEBUG" /D "_USRDLL" /D "PSGLICENSING_DLL_BUILD" /D "_VC80_UPGRADE=0x0710" /D "_WINDLL" /D "_MBCS" /D "_AFXDLL" /errorReport:prompt /WX- /Zc:forScope /Gd /Oy- /MD /Fa"Release\" /EHsc /nologo /Fo"Release\" /Fp"Release\PSGLicensing.pch"
    2.  
    3. *Linker:* /OUT:"SecretPah\PSGLicensing\Release\PSGLicensing.dll" /MANIFEST /PDB:"SecretPath\PSGLicensing\Release\PSGLicensing.pdb" /DYNAMICBASE:NO "..\CryptoPP\Release\cryptlib.lib" "SecretPath\CryptoPP\Release\cryptlib.lib" /DEF:".\PSGLicensing.def" /IMPLIB:"SecretPath\PSGLicensing\Release\PSGLicensing.lib" /DEBUG /DLL /MACHINE:X86 /OPT:REF /SAFESEH /INCREMENTAL:NO /PGD:"SecretPath\PSGLicensing\Release\PSGLicensing.pgd" /SUBSYSTEM:WINDOWS",5.01" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"Release\PSGLicensing.dll.intermediate.manifest" /OPT:ICF /ERRORREPORT:PROMPT /NOLOGO /TLBID:1
    To copy to clipboard, switch view to plain text mode 
    Here is jom output

    Qt Code:
    1. @ C:\Qt\Qt5.2.1\Tools\QtCreator\bin\jom.exe -f Makefile.Release
    2. link /NOLOGO /DYNAMICBASE /NXCOMPAT /INCREMENTAL:NO /DLL /MANIFEST /MANIFESTFILE:Release\PSGLicensing.dll.embed.manifest /OUT:Release\PSGLicensing.dll @C:\Users\ANDRIY~1.GLO\AppData\Local\Temp\PSGLicensing.dll.6212.16.jom
    3. Creating library Release\PSGLicensing.lib and object Release\PSGLicensing.exp
    4. GenerateRandomBlock.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall CryptoPP::CFB_CipherTemplate<class CryptoPP::AbstractPolicyHolder<class CryptoPP::CFB_CipherAbstractPolicy,class CryptoPP::CFB_ModePolicy> >::ProcessData(unsigned char *,unsigned char const *,unsigned int)" (?ProcessData@?$CFB_CipherTemplate@V?$AbstractPolicyHolder@VCFB_CipherAbstractPolicy@CryptoPP@@VCFB_ModePolicy@2@@CryptoPP@@@CryptoPP@@UAEXPAEPBEI@Z)
    5. GenerateRandomBlock.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall CryptoPP::CFB_CipherTemplate<class CryptoPP::AbstractPolicyHolder<class CryptoPP::CFB_CipherAbstractPolicy,class CryptoPP::CFB_ModePolicy> >::Resynchronize(unsigned char const *,int)" (?Resynchronize@?$CFB_CipherTemplate@V?$AbstractPolicyHolder@VCFB_CipherAbstractPolicy@CryptoPP@@VCFB_ModePolicy@2@@CryptoPP@@@CryptoPP@@UAEXPBEH@Z)
    6. GenerateRandomBlock.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall CryptoPP::CFB_CipherTemplate<class CryptoPP::AbstractPolicyHolder<class CryptoPP::CFB_CipherAbstractPolicy,class CryptoPP::CFB_ModePolicy> >::UncheckedSetKey(unsigned char const *,unsigned int,class CryptoPP::NameValuePairs const &)" (?UncheckedSetKey@?$CFB_CipherTemplate@V?$AbstractPolicyHolder@VCFB_CipherAbstractPolicy@CryptoPP@@VCFB_ModePolicy@2@@CryptoPP@@@CryptoPP@@MAEXPBEIABVNameValuePairs@2@@Z)
    7.  
    8. ...
    9.  
    10. Release\PSGLicensing.dll : fatal error LNK1120: 16 unresolved externals
    11. @
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,476
    Thanks
    252
    Thanked 708 Times in 698 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Linker errors when building DLL dependent on static lib(Crypto++)

    public: virtual void __thiscall CryptoPP::CFB_CipherTemplate<class CryptoPP::AbstractPolicyHolder<class ...
    This template is in the DLL you are wrapping CryptLib with? The error is telling you that it doesn't have the __declspec( dllimport ) or __declspec( dllexport ) declaration needed to export a method from a DLL (the __thiscall is the tipoff). Quite possibly one of the classes you use to construct the concrete template instantiation doesn't have the right declaration.

  3. #3
    Join Date
    Dec 2014
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Linker errors when building DLL dependent on static lib(Crypto++)

    Somehow, I got it solved. Here is the version of .pro file for CryptLib with which built library is linkable.

    Qt Code:
    1. QT -= core gui
    2. QMAKE_CFLAGS += /Zc:wchar_t /GL
    3.  
    4. TEMPLATE = lib
    5. TARGET = cryptlib
    6.  
    7. Release:DESTDIR = ./Release
    8. Debug:DESTDIR = ./Debug
    9.  
    10. CONFIG += staticlib
    11. DEFINES += _USING_V110_SDK71_ WINVER=0x0501 WIN32 _WINDOWS _MBCS USE_PRECOMPILED_HEADERS
    12. DEFINES -= UNICODE
    13.  
    14. DEPENDPATH += .
    15.  
    16. include(CryptoPP.pri)
    To copy to clipboard, switch view to plain text mode 

    So, all I did is added **USE_PRECOMPILED_HEADERS** to DEFINES and removed **PRECOMPILED_HEADER_FILE = pch.h**. I do not know how it actually helped, but it helped.

Similar Threads

  1. Replies: 5
    Last Post: 14th October 2010, 18:43
  2. linker errors from MinGW 4.4.0 for Qt 4.6.2
    By planetLars in forum Qt Tools
    Replies: 1
    Last Post: 15th April 2010, 20:30
  3. please help with linker errors
    By jimboqt in forum Qt Programming
    Replies: 1
    Last Post: 5th July 2007, 09:49
  4. Linker errors!!
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 25th April 2006, 08:14
  5. Linker Errors
    By MarkoSan in forum Qt Programming
    Replies: 5
    Last Post: 7th March 2006, 18:30

Tags for this Thread

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.