C++ 如何向 Visual Studio 项目添加其他库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4445418/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add additional libraries to Visual Studio project?
提问by Saad Masood
Allergro is an open souce C++ addon library for graphics manipulation. How do I add this library to my compiler?
Allergro 是一个用于图形操作的开源 C++ 插件库。如何将此库添加到我的编译器?
The instructions don't work for me as I have Windows 7. I don't know if the OS matters. I have the Visual Studio Express Edition. The library is a .dll file. How do I add it to my projects?
这些说明对我不起作用,因为我使用的是 Windows 7。我不知道操作系统是否重要。我有 Visual Studio 速成版。该库是一个 .dll 文件。如何将其添加到我的项目中?
回答by axlemke
For Visual Studio you'll want to right click on your project in the solution explorer and then click on Properties.
对于 Visual Studio,您需要在解决方案资源管理器中右键单击您的项目,然后单击Properties。
Next open Configuration Propertiesand then Linker.
接下来打开Configuration Properties,然后打开Linker。
Now you want to add the folder you have the Allegro libraries in to Additional Library Directories,
现在,您要将拥有 Allegro 库的文件夹添加到Additional Library Directory 中,
Linker-> Inputyou'll add the actual library files under Additional Dependencies.
Linker-> Input您将在Additional Dependencies下添加实际的库文件。
For the Header Files you'll also want to include their directories under C/C++-> Additional Include Directories.
对于头文件,您还需要在C/C++-> Additional Include Directories下包含它们的目录。
If there is a dllhave a copy of it in your main project folder, and done.
如果有一个DLL有它的复制品在主项目文件夹,并完成。
I would recommend putting the Allegro files in the your project folder and then using local references in for the library and header directories.
我建议将 Allegro 文件放在您的项目文件夹中,然后在库和头目录中使用本地引用。
Doing this will allow you to run the application on other computers without having to install Allergo on the other computer.
这样做将允许您在其他计算机上运行该应用程序,而无需在其他计算机上安装 Allergo。
This was written for Visual Studio 2008. For 2010 it should be roughly the same.
这是为 Visual Studio 2008 编写的。对于 2010,它应该大致相同。
回答by Billy ONeal
Add #pragma comment(lib, "Your library name here")
to your source.
添加#pragma comment(lib, "Your library name here")
到您的来源。
回答by Gemini14
Without knowing your compiler, no one can give you specific, step by step instructions, but the basic procedure is as follows:
在不了解您的编译器的情况下,没有人可以为您提供具体的分步说明,但基本过程如下:
Specify the path which should be searched in order to find the actual library (usually under Library Search Paths, Library Directories, etc. in the properties page)
Under linker options, specify the actual name of the library. In VS, you would write Allegro.lib (or whatever it is), on Linux you usually just write Allegro (prefixes/suffixes are added automatically in most cases). This is usually under "Libraries->Input", just "Libraries", or something similar.
Ensure that you have included the headers for the library and make sure that they can be found (similar process to that listed in step #1 and #2). If it is a static library, you should be good; if it's a DLL, you need to copy it in your project.
Mash the build button.
指定为找到实际库而应搜索的路径(通常在属性页面中的库搜索路径、库目录等下)
在链接器选项下,指定库的实际名称。在 VS 中,您将编写 Allegro.lib(或其他任何内容),在 Linux 上您通常只编写 Allegro(在大多数情况下会自动添加前缀/后缀)。这通常在“Libraries->Input”下,只是“Libraries”或类似的东西。
确保您已包含库的标头并确保可以找到它们(与步骤 #1 和 #2 中列出的过程类似)。如果是静态库,那应该不错;如果是 DLL,则需要将其复制到项目中。
捣碎构建按钮。
回答by Jonathan Wood
This description is very vague. What did you try, and how did it fail.
这个描述非常模糊。你尝试了什么,它是如何失败的。
To include a library with your project, you have to include it in the modules passed to the linker. The exact steps to do this depend on the tools you are using. That part has nothing to do with the OS.
要在您的项目中包含一个库,您必须将它包含在传递给链接器的模块中。执行此操作的确切步骤取决于您使用的工具。那部分与操作系统无关。
Now, if you are successfully compiling the library into your app and it doesn't run, that COULD be related to the OS.
现在,如果您成功地将库编译到您的应用程序中,但它没有运行,则可能与操作系统有关。