简体   繁体   English

链接Visual Studio 2013中的NuGet库

[英]Linking against NuGet Libraries in Visual Studio 2013

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: 嗨:在Visual Studio 2012 Professional,Update 4中,我可以通过创建一个新的Visual C ++项目(使用空白模板)并进入NuGet包管理器控制台并输入以下内容,轻松地创建一个新的OpenGL项目:

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

To grab the libraries for freeglut, glew, and glm (a header-only math library.) 获取freeglut,glew和glm(仅限标题的数学库)的库。

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. 然后在没有任何进一步配置的情况下,我可以点击大绿色构建按钮,所有内容都编译,链接和运行(在NuGet包中找到可再发行的.dll)并且工作正常。

In Visual Studio 2013, the same approach doesn't work: VS2013 complains that it cannot find freeglut.lib: 在Visual Studio 2013中,相同的方法不起作用:VS2013抱怨它找不到freeglut.lib:

LINK : fatal error LNK1104: cannot open file 'freeglut.lib' 链接:致命错误LNK1104:无法打开文件'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. 如果我手动编辑库路径并将DLL复制到构建输出目录,我可以让项目编译,但这似乎非常不方便。

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. 有趣的是,即使没有设置或更改任何内容,Visual Studio似乎足够聪明,可以查找 freeglut.lib,但它似乎不知道在哪里可以找到它。

Is this a per-package difficulty, or did VS2013 change something about how Visual Studio handles NuGet packages? 这是一个每包难度,还是VS2013改变了Visual Studio如何处理NuGet包?

I have same problem, after Install-Package freeglut 在Install-Package freeglut之后我遇到了同样的问题

Then I try to install another package: Install-Package nupengl.core 然后我尝试安装另一个包:Install-Package nupengl.core

It works 有用

What solved the linkerror for me was going to properties->linker->input->additional dependencies and added opengl32.lib . 为我解决了链接器错误的是找到properties-> linker- > input->其他依赖项并添加了opengl32.lib

You also need to make sure that the freeglut.dll/glew32.dll/glfw3.dll are in the same folder as your executable . 您还需要确保freeglut.dll / glew32.dll / glfw3.dll 可执行文件位于同一文件夹中。 This is what install-package nupengl.core does for you. 这就是install-package nupengl.core为您所做的。

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) 项目 - >属性 - >配置属性 - >参考包 - > freeglut->链接(选择静态)

Do the same for Referenced Packages->glew 对Referenced Packages-> glew执行相同的操作

Now, in Linker->General->Additional Library Directories: 现在,在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 $(SolutionDir)\\包\\ freeglut.2.8.1.15 \\建立\\本地\\ LIB \\ V110 \\ WIN32 \\调试\\静; $(SolutionDir)\\包\\ glew.1.9.0.1 \\建立\\本地\\ LIB \\ V110 \\ WIN32 \\调试\\静

The library versions may change, and the path may change a little, but this is what works for me as of 14-MAY-2015. 图书馆版本可能会发生变化,路径可能会有所变化,但这对我来说在2015年5月14日起适用。

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). 编辑:您仍然需要在链接器 - >输入 - >附加依赖项中包含“glew.lib”,因此,使用Referenced Package设置打扰似乎毫无意义(它适用于freeglut,但不适用于glew,并且如果您必须加入无论如何,额外的依赖关系,也可以添加freeglut)。

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 :) 对于动态链接,在Referenced Packages部分中,为freeglut&glew选择“Dynamic Linking”,并在Additional Library Directories设置中添加或替换每个包的库目录,并将DLL从可再发行目录复制到Projects输出目录,将调试DLL与Debug目录等相匹配。另外,省略XXX_STATIC #defines :)

The dynamic settings are a guess, but I know the static settings work. 动态设置是猜测,但我知道静态设置有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM