Linking against NuGet Libraries in Visual Studio 2013
Asked Answered
E

3

7

Hi: In Visual Studio 2012 Professional, Update 4, I can create a new OpenGL project pretty easily by creating a new Visual C++ project (using the blank template) and going into the NuGet Package Manager Console and typing:

Install-Package freeglut
Install-Package glew
Install-Package glm

To grab the libraries for freeglut, glew, and glm (a header-only math library.)

I can then create a simple example utilizing these libraries: (full example)

#include <GL/freeglut.h>
#include <GL/glew.h>
#include <glm/glm.hpp>

int main(int argc, char *argv[]) {
  ...
}

And then without any further configuration, I can hit the big green build button and everything compiles, links, and runs (finding the redistributable .dlls in the NuGet packages) and works fine.

In Visual Studio 2013, the same approach doesn't work: VS2013 complains that it cannot find freeglut.lib:

LINK : fatal error LNK1104: cannot open file 'freeglut.lib'

I can get the project to compile if I manually edit the Library path and copy the DLLs to the build output directory, but this seems severely less convenient.

Interestingly enough, even without setting or changing anything, Visual Studio seems smart enough to know to look for freeglut.lib, but it doesn't seem to know where to find it.

Is this a per-package difficulty, or did VS2013 change something about how Visual Studio handles NuGet packages?

Estoppel answered 5/2, 2014 at 5:46 Comment(2)
Trying to debug this by looking at the compiler flags in the terminal to spot any differences, but the 2012 and 2013 are virtually identical -- apart from references to vc110.pcb versus vc120.pcb for debugging symbols. I can't really seem to find any reason why the 2013 environment shouldn't work...Estoppel
Looking at the theoretical linker CLI opts in 2012 and 2013 versus the actual output, I've found that they are exactly identical, except the 2012 linker magically inserts the .lib files. I cannot find any setting difference to account for this: rifers.org/paste/show/2674Estoppel
S
11

I have same problem, after Install-Package freeglut

Then I try to install another package: Install-Package nupengl.core

It works

Sago answered 16/10, 2014 at 16:59 Comment(1)
I ran into the same problem, and installing nupengl.core solved the issue. But have you figured why?Shaquana
P
4

What solved the linkerror for me was going to properties->linker->input->additional dependencies and added opengl32.lib.

You also need to make sure that the freeglut.dll/glew32.dll/glfw3.dll are in the same folder as your executable. This is what install-package nupengl.core does for you.

Pga answered 5/8, 2015 at 10:12 Comment(0)
R
1

For static linking:

#define GLEW_STATIC
#define FREEGLUT_STATIC
#include <GL/glew.h>
#include <GL/freeglut.h>

Project->Properties->Configuration Properties->Referenced Packages->freeglut->Linkage (select static)

Do the same for Referenced Packages->glew

Now, in Linker->General->Additional Library Directories:

$(SolutionDir)\packages\freeglut.2.8.1.15\build\native\lib\v110\Win32\Debug\static;$(SolutionDir)\packages\glew.1.9.0.1\build\native\lib\v110\Win32\Debug\static

The library versions may change, and the path may change a little, but this is what works for me as of 14-MAY-2015.

EDIT: you still need to include "glew.lib" in Linker->Input->Additional Dependencies, so, bothering with the Referenced Package settings seems pointless (it works for freeglut, but not glew, and if you have to glew to the Additional Dependencies anyway, might as well just add freeglut, too).

For dynamic linking, in the Referenced Packages section, select "Dynamic Linking" for freeglut & glew, and either add or replace each package's library directory in the Additional Library Directories setting, and copy the DLL's from the redistributable directory to your Projects output directories, matching the debug DLL to the Debug directory, etc. Also, omit the XXX_STATIC #defines :)

The dynamic settings are a guess, but I know the static settings work.

Razid answered 14/5, 2015 at 21:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.