Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you add a C++ project reference in Visual Studio?

In C# it's pretty simple to add a project reference that will build the dependency, put the resulting assembly in the original's Debug/ directory and properly compile against that assembly.

So at the moment, I have a project with the Main() and a static library project in one solution. However, when I compile the Main() project and I look in the bin/Debug/ directory I don't find either the Static.lib file or the .obj files, which I think would need to be there, or something... I'm getting linker errors.

I think maybe I have to Configure the project to find the .obj and the .lib file produced by the static library project (which compiles fine, and actually produces those files.)

I'm missing something, and I'm not very well versed in Visual Studio with C++.

How do I add the reference in the Main project to use the library produced by the static library project?

like image 851
lucidquiet Avatar asked Jan 30 '13 16:01

lucidquiet


2 Answers

The first thing you'll have to unterstand is, that static libraries are nothing like .NET assemblies. They are linked into the .exe and are not distributed as separate entity.

Your linker errors are most likely a result of you not linking to the library.

There are several ways to define libraries that have to be linked. One is int the project settings under linker -> input -> additional dependencies, the other would be the cheap route via #pragma comment(lib, "path to library")

like image 51
MFH Avatar answered Nov 07 '22 21:11

MFH


You can add the name of the .lib files you need by going in project property->Linker->Input->Additional Dependencies

Then you will have to give the folder where your library is in VC++ Directories->Library Directerories.

like image 45
Étienne Avatar answered Nov 07 '22 21:11

Étienne