簡體   English   中英

Visual Studio 2008 IDE-靜態鏈接C Dll庫

[英]Visual Studio 2008 IDE - Static Linking a C Dll Library

我在此%&$ ^&VS IDE中遇到了挫折^ Frustraion。 我正在使用Visual C ++ 2008 3.5 SP1(但如果需要也可以使用專業版,但我不想使用loadlibrary())

我有一個用另一種語言(實際上基本不是C)創建的測試Dll,它包含一個CDECL函數,該函數將'int'添加到'double'中。 我真的很想使用STDCALL向int浮點數中添加一個int,但是如果可以讓前一個首先工作,那將是一個重大成就。

我已經廣泛閱讀並嘗試過: http : //support.microsoft.com/kb/313981 http://www.codeproject.com/KB/DLL/loadingdll.aspx 鏈接到靜態庫,該庫 靜態 鏈接到靜態庫, 並且動態鏈接使用不同版本的Visual Studio生成的DLL

我為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)" (?AddTwoNum@@YAHHN@Z) 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 ==========

您可以轉到:

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

然后,將您的.lib添加到“其他依賴項”中。

此外,您可以

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

在您的.cpp文件中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM