Visual Studio 2008 IDE - 静态链接 C Dll 库

发布于 2024-08-06 10:16:47 字数 2069 浏览 4 评论 0原文

我正在经历挫败感 ^ 挫败感与这个 %&$^& VS IDE。 我正在使用 Visual C++ 2008 3.5 SP1(但如果需要的话我也有专业版,并且我不想使用 loadlibrary())

我有一个用另一种语言(实际上不是 C)创建的测试 Dll,其中包含 CDECL将“int”添加到“double”的函数。我真的很想使用 STDCALL 将 int 添加到 float,但如果能让前者首先工作,那将是一项重大成就。

我广泛阅读并尝试过: http://support.microsoft.com/kb/313981 http://www.codeproject.com/KB/DLL/loadingdll.aspx 链接到静态库,该静态库链接到静态库库 静态和动态链接使用不同版本生成的 DLL 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)" (?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 ==========

I am experiencing Frustration ^ Frustraion with this %&$^& VS IDE.
I am using Visual C++ 2008 3.5 SP1 (but I also have the pro edition if that is needed and I dont want to use loadlibrary())

I have a test Dll created in another language (basic not C in fact) that contains a CDECL function that adds an 'int' to a 'double'. I would really like to add an int to a float using STDCALL, but if can get the former to work first that would be a major acheivement.

I have read extensively and tried:
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

I wrote a nice header file for the AddShow.dll called AddShow.h

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

Then I used this nifty tool to create the .lib file:
http://www.binary-soft.com/dll2lib/dll2lib.htm

Now what?

I tried right click and 'Add' then 'Class" then 'Componant Class' then specifying the path and name of the dll, but I get 8 miles of bloat and the entire windows toolbox and a new AddShow.cpp file.

My C++ code is really simply:

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;
}

How do I just get the IDE to link the .lib file?

ADDED:

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 ==========

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离旧人 2024-08-13 10:16:47

您可以前往:

项目属性->链接器->输入

然后将您的.lib 添加到“附加依赖项”中。

此外,您可以放入

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

.cpp 文件。

You can go to:

Project Properties -> Linker -> Input

Then add your .lib to the "Additional Dependencies".

Additionally, you can put

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

in your .cpp file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文