How to add additional libraries to Visual Studio project?
Asked Answered
R

4

102

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

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?

Rugg answered 14/12, 2010 at 23:41 Comment(2)
You will probably have to include the appropriate header files for what you need and link the libraries (.dll files on windows) at compilation.Bostic
@RageD: Libraries, even DLLs, link via .lib files on Windows.Relief
E
157

For Visual Studio you'll want to right click on your project in the solution explorer and then click on 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,

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.

If there is a dll have a copy of it in your main project folder, and done.

I would recommend putting the Allegro files in the your project folder and then using local references in for the library and header directories.

Doing this will allow you to run the application on other computers without having to install Allergo on the other computer.

This was written for Visual Studio 2008. For 2010 it should be roughly the same.

Electrochemistry answered 14/12, 2010 at 23:42 Comment(3)
i use eclipse too. (MinGW). does it apply to that too?Rugg
i use eclipse too. (MinGW). does it apply to that too? Not exactly there will be similar instructions on a different IDE and toolchain but I would not expect the dialogs to be the same for a different IDE.Gynecology
Following the steps you suggested i am getting two errors: LNK1104 cannot open file 'chess.lib' MSB6006 "link.exe" exited with code 1104Gaston
N
61

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

Noam answered 15/12, 2010 at 2:3 Comment(3)
That helped solve the problem in Visual Studio 2012. Thank you!Califate
Yep, works in VS 2017, if the lib is in a standard path, it is picked up automatically!Dairen
It worker for the lib: #pragma comment(lib, "Winmm.lib"). But it didn't worked by adding the library in the "Additional Dependencies." option. Why is that?Valenciavalenciennes
E
6

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.

  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.

  4. Mash the build button.

Embolus answered 14/12, 2010 at 23:50 Comment(0)
U
3

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.

Usm answered 14/12, 2010 at 23:48 Comment(1)
i got this zip file. i was told follow the instructions in the zip file. first you had to cmake. so i installed cmake but it didnt go accordingly.Rugg

© 2022 - 2024 — McMap. All rights reserved.