c++ - 创建静态库并将其链接到 Visual Basic Windows 窗体应用程序

标签 c++ visual-studio-2010 static-libraries sln-file

我在 Visual Studio2010 中创建了两个程序。

一个是 Visual Basic Windows 窗体应用程序(用户前端),提示用户选择文件路径(.bin 文件)。 第二个程序是一个 Visual Studio C++ 应用程序,它有一个 ReadFile() 函数,它读取二进制文件的内容并执行一些数学计算。

我想从第二个程序生成一个静态库 (.lib) 并将其与第一个程序(用户前端)链接。 用户前端程序必须能够将文件路径传递给静态库中的ReadFile() 函数

我已经分别创建了这两个程序,但发现很难创建静态库并将其与用户前端链接。 我该怎么做??

P.S:这听起来可能很愚蠢,但我的目标是学习如何创建静态库并将其链接到 Windows 窗体应用程序。

The user front end application which prompts the user to select the file.

最佳答案

执行以下步骤创建静态库项目:

  1. On the menu bar, choose File, New, Project.
  2. In the left pane of the New Project dialog box, expand Installed, Templates, Visual C++, and then select Win32.
  3. In the center pane, select Win32 Console Application.
  4. Specify a name for the project—for example, MathFuncsLib—in the Name box. Specify a name for the solution—for example, StaticLibrary—in the Solution Name box. Choose the OK button.
  5. On the Overview page of the Win32 Application Wizard dialog box, choose the Next button.
  6. On the Application Settings page, under Application type, select Static library.
  7. On the Application Settings page, under Additional options, clear the Precompiled header check box.
  8. Choose the Finish button to create the project.

创建引用静态库的 C++ 控制台应用程序

  1. On the menu bar, choose File, New, Project.
  2. In the left pane, under Visual C++, select Win32.
  3. In the center pane, select Win32 Console Application.
  4. Specify a name for the project—for example, MyExecRefsLib—in the Name box. In the drop-down list next to Solution, select Add to Solution. This adds the new project to the solution that contains the static library. Choose the OK button.
  5. On the Overview page of the Win32 Application Wizard dialog box, choose the Next button.
  6. On the Application Settings page, under Application type, select Console application.
  7. On the Application Settings page, under Additional options, clear the Precompiled header check box.
  8. Choose the Finish button to create the project.

来源:https://msdn.microsoft.com/en-us/library/ms235627.aspx

您可以在上面的链接中看到更多信息,如何在您的项目中使用代码。

更新评论中的以下问题:

在解决方案资源管理器中右键单击您的项目,然后单击属性

接下来打开配置属性,然后打开链接器

现在您想将拥有 Allegro 库的文件夹添加到其他库目录中,

Linker -> Input 您将在Additional Dependencies 下添加实际的库文件。

对于头文件,您还需要在 C/C++ -> 附加包含目录下包含它们的目录。

在主项目文件夹中复制一份 lib 文件,然后完成

我希望它能支持你的问题。

关于c++ - 创建静态库并将其链接到 Visual Basic Windows 窗体应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34585359/

相关文章:

c++ - 是否可以将存储在双字中的十六进制与 getasynckeystate 一起使用?

C++ 使 char 数组在输入时识别空格

来自 typedef 的 C++ 模板错误

visual-studio-2010 - Visual Studio 2010 Beta 2开始要求提升

c - dumpbin 报告静态库的错误目标架构

c++ - 无法使用 CMemFile::Detach() 复制 CMemFile 中存在的数据

c++ - 无法遍历树 - 节点被重新遍历了很多次但仍然是非循环的

visual-studio-2010 - 如何使用条件文件复制设置安装程序项目

c - 确定库版本?

ios - 在 OSX 和 IOS 应用程序之间共享代码的最佳实践