我在 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.
最佳答案
执行以下步骤创建静态库项目:
- On the menu bar, choose File, New, Project.
- In the left pane of the New Project dialog box, expand Installed, Templates, Visual C++, and then select Win32.
- In the center pane, select Win32 Console Application.
- 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.
- On the Overview page of the Win32 Application Wizard dialog box, choose the Next button.
- On the Application Settings page, under Application type, select Static library.
- On the Application Settings page, under Additional options, clear the Precompiled header check box.
- Choose the Finish button to create the project.
创建引用静态库的 C++ 控制台应用程序
- On the menu bar, choose File, New, Project.
- In the left pane, under Visual C++, select Win32.
- In the center pane, select Win32 Console Application.
- 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.
- On the Overview page of the Win32 Application Wizard dialog box, choose the Next button.
- On the Application Settings page, under Application type, select Console application.
- On the Application Settings page, under Additional options, clear the Precompiled header check box.
- 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/