如何在c++中添加额外的库?

[英]How do I add additional libraries in C++?


Allergro is an open souce C++ addon library for graphics manipulation. How do I add this library to my compiler?

Allergro是一个用于图形处理的开放的souce c++ addon库。如何将这个库添加到编译器中?

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 Express Edition。库是一个.dll文件。我如何将它添加到我的项目中?

4 个解决方案

#1


59  

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 Properties and then Linker.

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

Now you want to add the folder you have the Allegro libraries in to Additional Library Directories,

现在你想要添加文件夹你有Allegro库到其他库目录中,

Linker -> Input you'll add the actual library files under Additional Dependencies.

链接器->输入,您将在附加的依赖项下添加实际的库文件。

For the Header Files you'll also want to include their directories under C/C++ -> Additional Include Directories.

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

If there is a dll have 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年的情况应该大致相同。

#2


22  

Add #pragma comment(lib, "Your library name here") to your source.

在源代码中添加#pragma注释(lib,“您的库名”)。

#3


2  

Without knowing your compiler, no one can give you specific, step by step instructions, but the basic procedure is as follows:

在不了解编译器的情况下,没有人能够一步一步地给出具体的说明,但是基本的步骤如下:

  1. 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)

    指定应该搜索的路径以便查找实际的库(通常在库搜索路径、库目录等属性页中)

  2. 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.

    在链接器选项下,指定库的实际名称。在VS中,你会写快板。lib(或者别的什么),在Linux上你通常只写快板(在大多数情况下,前缀/后缀是自动添加的)。这通常是在“库->输入”、“库”或类似的东西下。

  3. 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.

    确保包含了库的标题,并确保可以找到它们(类似于第1步和第2步中列出的过程)。如果它是一个静态库,你应该是好的;如果是DLL,则需要在项目中复制它。

  4. Mash the build button.

    土豆泥构建按钮。

#4


1  

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.

现在,如果你成功地将库编译到你的应用程序中,而它没有运行,这可能与操作系统有关。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2010/12/14/4329aa9fec353401c3af2c063028bced.html



 
粤ICP备14056181号  © 2014-2019 ITdaan.com

赞助商广告