c++ - glfw 和 MSVS 2012 的链接器错误

标签 c++ visual-studio-2012 glfw

我正在尝试使用 MSVS 2012 设置 glfw。

我从http://www.glfw.org/download.html下载了最新版本的glfw (32 位)。 在下一步中,我创建了一个包含以下内容的新属性表:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup />
  <ItemDefinitionGroup>
    <ClCompile>
      <AdditionalIncludeDirectories>$(glfw_DIR)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ClCompile>
    <Link>
      <AdditionalLibraryDirectories>$(glfw_DIR)\lib-msvc120;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
      <AdditionalDependencies>glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup />
</Project>

然后我尝试运行以下代码:

#include <GLFW/glfw3.h>
#include <thread>

int main()
{
    glfwInit();
    std::this_thread::sleep_for(std::chrono::seconds(1));
    glfwTerminate();
}

并收到以下输出:

1>------ Erstellen gestartet: Projekt: openGL_Basic_flow, Konfiguration: Debug Win32 ------
1>LINK : warning LNK4098: Standardbibliothek "MSVCRT" steht in Konflikt mit anderen Bibliotheken; /NODEFAULTLIB:Bibliothek verwenden.
1>glfw3.lib(window.obj) : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "__imp__glClear@4" in Funktion "_glfwCreateWindow".
1>glfw3.lib(context.obj) : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "__imp__glGetIntegerv@8" in Funktion "__glfwRefreshContextAttribs".
1>glfw3.lib(context.obj) : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "__imp__glGetString@4" in Funktion "_glfwExtensionSupported".
1>glfw3.lib(wgl_context.obj) : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "__imp__wglCreateContext@4" in Funktion "__glfwCreateContext".
1>glfw3.lib(wgl_context.obj) : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "__imp__wglDeleteContext@4" in Funktion "__glfwDestroyContext".
1>glfw3.lib(wgl_context.obj) : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "__imp__wglGetProcAddress@4" in Funktion "__glfwPlatformGetProcAddress".
1>glfw3.lib(wgl_context.obj) : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "__imp__wglMakeCurrent@8" in Funktion "__glfwPlatformMakeContextCurrent".
1>glfw3.lib(wgl_context.obj) : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "__imp__wglShareLists@8" in Funktion "__glfwCreateContext".
1>glfw3.lib(win32_time.obj) : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "__dtoul3" in Funktion "__glfwPlatformSetTime".
1>glfw3.lib(win32_time.obj) : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "__ultod3" in Funktion "__glfwInitTimer".
1>C:\Projektmappe\Debug\openGL_Basic_flow.exe : fatal error LNK1120: 10 nicht aufgelöste Externe
========== Erstellen: 0 erfolgreich, 1 fehlerhaft, 0 aktuell, 0 übersprungen ==========

我还尝试使用此处提到的解决方法修复它:Compiling GLFW with Visual Studio 2012 但这没有帮助。输出更改为以下内容:

1>------ Erstellen gestartet: Projekt: openGL_Basic_flow, Konfiguration: Debug Win32 ------
1>  main.cpp
1>LINK : warning LNK4098: Standardbibliothek "MSVCRT" steht in Konflikt mit anderen Bibliotheken; /NODEFAULTLIB:Bibliothek verwenden.
1>glfw3.lib(win32_time.obj) : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "__dtoul3" in Funktion "__glfwPlatformSetTime".
1>glfw3.lib(win32_time.obj) : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "__ultod3" in Funktion "__glfwInitTimer".
1>C:\Projektmappe\Debug\openGL_Basic_flow.exe : fatal error LNK1120: 2 nicht aufgelöste Externe
========== Erstellen: 0 erfolgreich, 1 fehlerhaft, 0 aktuell, 0 übersprungen ==========

还有其他想法吗?

最佳答案

您为 Visual Studio 2012 使用了错误的二进制文件。正确的二进制文件位于 lib-msvc110 文件夹中。当您有 2 位或 3 位数字版本时,您需要始终保持谨慎,因为它们与年份不匹配(它们仅适用于 2010 年)。

  • VC90 = Visual Studio 2008
  • VC100 = Visual Studio 2010
  • VC110 = Visual Studio 2012。
  • VC120 = Visual Studio 2013。

关于c++ - glfw 和 MSVS 2012 的链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27756498/

相关文章:

c++ - 使用 libpcap 收集有关连接的统计信息

c++ - GLFW 设置窗口图标

c++ - glfwSwapInterval(1) 无法启用 vsync?

c++ - 无法将 QMetaMethod 与 lambda 连接起来

c++ - 在填充成员 vector 期间避免复制构造函数

c++ - 具有临时子表达式的临时对象的生命周期,绑定(bind)到一个引用

c# - 为什么我的 C# 标签文本值不更新?

visual-studio - 使用多个文件中的脚本创建 PowerScript 模块

azure - TFS预览: How do I setup a hosted build controller

multithreading - LWJGL3共享上下文抛出 “GLFW_VERSION_UNAVAILABLE”