2009-10-03 75 views
0

我遇到挫折^挫敗與此%& $^& VS IDE。我使用Visual C++ 2008 3.5 SP1(但我也有專業版,如果需要,我不想使用loadlibrary())Visual Studio 2008 IDE - 靜態鏈接一個C Dll庫

我有一個測試在另一種語言(基本不C ),它包含一個將'int'添加到'double'的CDECL函數。我真的很想使用STDCALL爲浮點數添加一個int,但是如果能夠讓前者首先工作,那將是一個重要的成就。

我已經廣泛閱讀和嘗試: http://support.microsoft.com/kb/313981 http://www.codeproject.com/KB/DLL/loadingdll.aspx Linking to a static lib that links to a static lib statically and dynamically linking DLLs generated with different versions of Visual Studio

我寫了一個不錯的頭文件的AddShow.dll稱爲AddShow.h

DLLAPI int __cdecl AddTwoNum(int n, double f); 

然後我用這個漂亮的工具來創建.lib文件: http://www.binary-soft.com/dll2lib/dll2lib.htm

現在呢?

我嘗試了右鍵單擊和'添加'然後'類'然後'組件類',然後指定DLL的路徑和名稱,但我得到8英里的膨脹和整個Windows工具箱和一個新的AddShow.cpp文件。

我的C++代碼是真的簡單:

extern int __cdecl AddTwoNum(int n, double f); 

int main() 
{ 
    int n, RetVal; 
    double d; 

     n = 33; 
     d = 66.6; 

    RetVal = AddTwoNum(n, d); 

    cout << "RetVal=" << RetVal; 

    return 0; 
} 

如何我只是得到了IDE來鏈接的.lib文件

新增:?

after linking (.lib file is in the debug file) I get the following error: 
Compiling... 
main.cpp 
Linking... 
main.obj : error LNK2019: unresolved external symbol "int __cdecl AddTwoNum(int,double)" ([email protected]@[email protected]) referenced in function _main 
C:\C++\FirstDll\Debug\FirstDll.exe : fatal error LNK1120: 1 unresolved externals 
Build log was saved at "file://c:\C++\FirstDll\FirstDll\Debug\BuildLog.htm" 
FirstDll - 2 error(s), 0 warning(s) 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 
+0

您可能想要開始使用CMake生成解決方案文件,而不是點擊以終止解決方案管理器。我覺得CMake不那麼刺激。 – liori 2009-10-03 00:21:41

回答

2

你可以去:

項目屬性 - >鏈接器 - >輸入

那麼你的.lib添加到 「附加依賴」。

此外,你可以把

#pragma comment(lib, "<your .lib>") 

在.cpp文件。

+0

謝謝你,但我得到上面顯示的編譯錯誤。 – 2009-10-06 21:20:55

+1

在你的錯誤中,AddTwoNum的名字被損壞(?AddTwoNum @@ YAHHN @ Z) 嘗試將你的AddTwoNum聲明放在extern「C」{} – Kevin 2009-10-07 03:59:23