2013-03-21 101 views
3

使用整個LibTomCrypt源代碼,我已經構建了一個Visual Studio 2010庫文件,它編譯時沒有問題。但是,創建與TomCrypt庫鏈接的一個簡單的測試控制檯應用程序的時候,我收到一個鏈接錯誤以下代碼:Visual Studio 2010 LibTomCrypt構建或庫鏈接錯誤

測試代碼

#include <stdio.h> 
#include <tomcrypt.h> 

int main() 
{ 
    int Cipher; 

    register_cipher(&aes_desc); 
    Cipher = find_cipher("aes"); 
    if(Cipher != CRYPT_OK) 
     return 0; 

    printf("Cipher name: %s\n", cipher_descriptor[ Cipher ].name); 
    unregister_cipher(&aes_desc); 

    return 0; 
} 

鏈接錯誤

error LNK1120: 1 unresolved externals 
error LNK2001: unresolved external symbol _aes_desc 

有趣的是,調試庫構建與測試代碼完美配合。它是版本內部版本tomcrypt.lib似乎缺少一些符號。

現在,我並不是新建構和使用庫文件,但我想知道,是否有一些特定的編譯器標誌或預防措施,我可以在發佈模式下構建庫,並讓它在我的測試程序中正確鏈接?通過某種編譯器優化的方式,LibTomCrypt代碼中定義的靜態aes_desc結構是否會從庫的發佈版本中丟失?

我希望有人能爲我自己和遇到此問題的任何人提供一些見解。

+0

您是否使用'gcc'來構建靜態庫的代碼?因爲如果是這樣,那麼它將無法工作。 – Max 2013-05-06 20:26:12

回答

2

我今天剛碰到相關問題。 Visual Studio的項目配置包括構建aes.c的自定義步驟,但只包含Debug構建。一旦我爲Release版本製作了可比較的條款,一切都很好。

在文本編輯器中打開Visual Studio 2010項目,並將自定義生成步驟替換爲下面的步驟。這也將修復調試版本的一些警告:

<CustomBuild Include="src\ciphers\aes\aes.c"> 
     <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">cl /nologo /MTd /W3 /Gm /EHsc /ZI /Od /I "src\headers" /I "..\libtommath" /D "_DEBUG" /D "LTM_DESC" /D "WIN32" /D "_MBCS" /D "_LIB" /D "LTC_SOURCE" /D "USE_LTM" /Fp"Debug/libtomcrypt.pch" /Fo"Debug/" /Fd"Debug/" /FD /RTC1 /c %(FullPath) 
cl /nologo /DENCRYPT_ONLY /MTd /W3 /Gm /EHsc /ZI /Od /I "src\headers" /I "..\libtommath" /D "_DEBUG" /D "LTM_DESC" /D "WIN32" /D "_MBCS" /D "_LIB" /D "LTC_SOURCE" /D "USE_LTM" /Fp"Debug/libtomcrypt.pch" /Fo"Debug/aes_enc.obj" /Fd"Debug/" /FD /RTC1 /c %(FullPath)</Command> 
     <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Debug/aes.obj;Debug/aes_enc.obj;%(Outputs)</Outputs> 
    </CustomBuild> 
    <CustomBuild Include="src\ciphers\aes\aes.c"> 
     <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">cl /nologo /MT /W3 /O2 /I "src\headers" /I "..\libtommath" /D "NDEBUG" /D "LTM_DESC" /D "WIN32" /D "_MBCS" /D "_LIB" /D "LTC_SOURCE" /D "USE_LTM" /Fp"Release/libtomcrypt.pch" /Fo"Release/" /Fd"Release/" /FD /c %(FullPath) 
cl /nologo /DENCRYPT_ONLY /MT /W3 /O2 /I "src\headers" /I "..\libtommath" /D "NDEBUG" /D "LTM_DESC" /D "WIN32" /D "_MBCS" /D "_LIB" /D "LTC_SOURCE" /D "USE_LTM" /Fp"Release/libtomcrypt.pch" /Fo"Release/aes_enc.obj" /Fd"Release/" /FD /c %(FullPath)</Command> 
     <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Release/aes.obj;Release/aes_enc.obj;%(Outputs)</Outputs> 
    </CustomBuild> 
+0

你採取了哪些步驟來做出適當的規定? – 2013-08-15 22:06:22

+0

@ by.axiom查看編輯答案中的所需更改。 – astraujums 2014-04-16 11:42:51