C++ Visual Studio 2012 - 错误 LNK1104:无法打开文件“glew32.lib”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20873321/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:22:28  来源:igfitidea点击:

Visual Studio 2012 - error LNK1104: cannot open file 'glew32.lib'

c++openglvisual-studio-2012glew

提问by Sad CRUD Developer

I am having issues compiling a basic openGL program on VS 2012. I get a build error upon compiltation giving me:

我在 VS 2012 上编译基本的 openGL 程序时遇到问题。我在编译时遇到构建错误,提示我:

1>LINK : fatal error LNK1104: cannot open file 'glew32.lib'

I followed the instructions given to me by the documentation for GLEW.

我遵循了 GLEW 文档给我的说明。

In your OpenGL project open Project -> Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies -> add glew32.lib.

Also you must include #include in your sources; For that add path to your glew folder: Project -> Properties -> Configuration Properies -> General -> VC++ Directories -> Include Directories and Library Directories;

C/C++ Tab -> General -> Additional Include Directories - Add lib folder there

在你的 OpenGL 项目中打开 Project -> Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies -> add glew32.lib。

此外,您必须在来源中包含 #include;为此,将路径添加到您的 glew 文件夹:项目 -> 属性 -> 配置属性 -> 常规 -> VC++ 目录 -> 包含目录和库目录;

C/C++ Tab -> General -> Additional Include Directories - 在那里添加 lib 文件夹

I have also added the glew32.dll onto my Debug folder within my project folder along with the executable. So far I keep getting this error.

我还将 glew32.dll 与可执行文件一起添加到我的项目文件夹中的 Debug 文件夹中。到目前为止,我一直收到此错误。

If you need any more further clarification of the steps I have done please don't hesitate to ask

如果您需要进一步说明我所做的步骤,请随时询问

回答by Andon M. Coleman

In all honesty, there is no real benefit to using the DLL version of glew (short of reduced executable size, but this hardly matters on modern Windows PCs).

老实说,使用 glew 的 DLL 版本并没有真正的好处(缺少减小的可执行文件大小,但这在现代 Windows PC 上几乎不重要)。

It is not like you can simply drop a new version of the DLL into your application and use extensions that you never used before. Likewise, bug fixes are so infrequent/unnecessary with a library that basically just parses the extension spec. files that using the DLL as a means of fixing extension loading bugs in shipped software is also not practical. Statically linking to glew (this means glew32s.lib) makes much more sense in the long run.

这不像您可以简单地将新版本的 DLL 放入您的应用程序并使用您以前从未使用过的扩展。同样,对于一个基本上只解析扩展规范的库,错误修复是如此罕见/不必要。使用 DLL 作为修复附带软件中的扩展加载错误的方法的文件也不实用。glew32s.lib从长远来看,静态链接到 glew(这意味着)更有意义。

The static linking library is also more portable on Windows, it will work with MSVC and MinGW (whereas the DLL library only works with MSVC). Link against glew32sand put that in whatever directory you decided to use for additional library dependencies.

静态链接库在 Windows 上也更具可移植性,它适用于 MSVC 和 MinGW(而 DLL 库仅适用于 MSVC)。链接glew32s并将其放在您决定用于其他库依赖项的任何目录中。



这是我编写的使用 glew 的项目的示例解决方案配置。我已经为这个特定软件建立了一个约定,其中编译时依赖项存储在platform/<Subsystem>platform/<Subsystem>. 因此,我有glew32s.libglew32s.lib(32 位)和glew64s.libglew64s.lib(64 位)./Epsilon/platform/OpenGL/glew{32|64}s.lib./Epsilon/platform/OpenGL/glew{32|64}s.lib

  enter image description here

  在此处输入图片说明

回答by David

It happened to me under this situation, I clean the solution and build it again, then many errors like LNK1104 occur.

在这种情况下发生在我身上,我清理解决方案并重新构建它,然后出现许多像LNK1104这样的错误。

After trying to restart IIS, I build solution successfully without LNK1104 errors. I do not know why, but restarting IIS takes much more time than normal, so I guess something is used by other IIS worker process.

尝试重新启动 IIS 后,我成功构建了解决方案,没有出现 LNK1104 错误。我不知道为什么,但重新启动 IIS 比正常需要更多的时间,所以我猜其他 IIS 工作进程使用了​​某些东西。

Just give a shot to see if this magic happens on you.

试一试,看看这种魔法是否会发生在你身上。

回答by Mohith Maratt

Steps to Use Classes form another project (Add header and solver linker errors)

使用类形成另一个项目的步骤(添加标头和求解器链接器错误)

  1. To be able to add the header from another project, first go to "Properties > c++ > General > Additional Include Directories"and add the directory that contains the header. Now you will be able to add the header of the class from the other project, but running the project will still cause Linker Errors.

  2. Add __declspec(dllexport)before the class you are using for the other project. This can be added in the header file of that class. This should be added right before the function or variable or class name. Now you will get a lib file. (if placed in wrong place, you can get this warning: https://msdn.microsoft.com/en-us/library/eehkcz60.aspx)

  3. "Properties > Linker > Additional Library Directories". Specify the location of the lib file that is generated.

  4. "Properties > Linker > Input > Additional Dependencies”: Add the name of the lib file.

  1. 为了能够从另一个项目添加标题,首先转到“属性 > c++ > 常规 > 附加包含目录”并添加包含标题的目录。现在您将能够添加来自其他项目的类的头文件,但运行该项目仍会导致链接器错误。

  2. 在用于其他项目的类之前添加__declspec(dllexport)。这可以添加到该类的头文件中。这应该在函数或变量或类名之前添加。现在你会得到一个lib文件。(如果放在错误的地方,你会得到这个警告:https: //msdn.microsoft.com/en-us/library/eehkcz60.aspx

  3. “属性 > 链接器 > 附加库目录”。指定生成的 lib 文件的位置。

  4. “属性 > 链接器 > 输入 > 附加依赖项”:添加 lib 文件的名称。

回答by yoad w

This question is old and marked solved, but I had a similar problem symptoms with a completely different solution. So just in case anyone else stumbles in here:
It appeared that because I had 2 projects under one solution (a dll and an exe), the building order was mixed (from the output window):

这个问题很旧并且标记为已解决,但我有一个完全不同的解决方案的类似问题症状。所以以防万一其他人在这里绊倒:
似乎是因为我在一个解决方案下有 2 个项目(一个 dll 和一个 exe),所以构建顺序是混合的(来自输出窗口):

1> Rebuilding project1..
2> Rebuilding project1..
1> file1.cpp
2> file1.cpp

and so on. By the message you copied, it appears you too have more than one project under one solution. One project was looking for the *.lib file that the other build hadn't created yet.
Solution:
Right click on "main" project -> Build Dependencies -> Project Dependencies.. -> Mark which project the main one depends on.

等等。根据您复制的消息,您似乎在一个解决方案下也有多个项目。一个项目正在寻找另一个构建尚未创建的 *.lib 文件。
解决方法:
右键单击“main”项目-> Build Dependencies -> Project Dependencies.. -> 标记主要依赖的项目。

回答by FuzzyBunnySlippers

This sounds like the library has been specified as a dependency, but the linker/additional search path(s) has not been set to include the directory where the library is located.

这听起来像库已被指定为依赖项,但链接器/其他搜索路径尚未设置为包括库所在的目录。

This may help.

这可能会有所帮助