GLFW - ウィンドウを開けませんでした [重複] 質問する

GLFW - ウィンドウを開けませんでした [重複] 質問する

クロスプラットフォームのフレームワーク/ライブラリを探しているうちに、GLFW が何度も話題になりました。そこで、試してみることにしました。しかし、どうやらウィンドウを初期化することすらできないようです。:-/

#include <cstdlib>
#include <ctime>
#include <gl/glfw.h>

int main(int argc, char *argv[])
{
    int running = GL_TRUE;
    srand(time(NULL));

    if (!glfwInit())
        exit(EXIT_FAILURE);

    if (!glfwOpenWindow(300, 300, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    while (running)
    {
        glClear(GL_COLOR_BUFFER_BIT);
        glClearColor(rand() % 255 + 1, rand() % 255 + 1, rand() % 255 + 1, 0);

        glfwSwapBuffers();

        running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED);
    }

    glfwTerminate();

    exit(EXIT_SUCCESS);
}

これを MVC++ 2010 で入力し、ヘッダーと 2 つの lib ファイルをリンクしました (DLL ファイルが 1 つあったので、それを SysWOW64 フォルダーに配置しました)。すると、次のエラーが発生します。

1>------ Build started: Project: glfwTest, Configuration: Debug Win32 ------
1> test.cpp
1>c:\users\andrew\documents\visual studio 2010\projects\glfwtest\glfwtest\test.cpp(8): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>c:\users\andrew\documents\visual studio 2010\projects\glfwtest\glfwtest\test.cpp(22): warning C4244: 'argument' : conversion from 'int' to 'GLclampf', possible loss of data
1>c:\users\andrew\documents\visual studio 2010\projects\glfwtest\glfwtest\test.cpp(22): warning C4244: 'argument' : conversion from 'int' to 'GLclampf', possible loss of data
1>c:\users\andrew\documents\visual studio 2010\projects\glfwtest\glfwtest\test.cpp(22): warning C4244: 'argument' : conversion from 'int' to 'GLclampf', possible loss of data
1>test.obj : error LNK2019: unresolved external symbol __imp__glClearColor@16 referenced in function _main
1>GLFW.lib(win32_window.obj) : error LNK2001: unresolved external symbol __imp__glClearColor@16
1>test.obj : error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function _main
1>GLFW.lib(window.obj) : error LNK2001: unresolved external symbol __imp__glClear@4
1>GLFW.lib(win32_window.obj) : error LNK2001: unresolved external symbol __imp__glClear@4
1>GLFW.lib(win32_window.obj) : error LNK2019: unresolved external symbol __imp__wglGetProcAddress@4 referenced in function _initWGLExtensions
1>GLFW.lib(win32_glext.obj) : error LNK2001: unresolved external symbol __imp__wglGetProcAddress@4
1>GLFW.lib(win32_window.obj) : error LNK2019: unresolved external symbol __imp__wglMakeCurrent@8 referenced in function _createWindow
1>GLFW.lib(win32_window.obj) : error LNK2019: unresolved external symbol __imp__wglCreateContext@4 referenced in function _createContext
1>GLFW.lib(win32_window.obj) : error LNK2019: unresolved external symbol __imp__wglDeleteContext@4 referenced in function _destroyWindow
1>GLFW.lib(win32_window.obj) : error LNK2019: unresolved external symbol __imp__glGetFloatv@8 referenced in function __glfwPlatformSetWindowSize
1>GLFW.lib(win32_window.obj) : error LNK2019: unresolved external symbol __imp__glGetIntegerv@8 referenced in function __glfwPlatformSetWindowSize
1>GLFW.lib(glext.obj) : error LNK2001: unresolved external symbol __imp__glGetIntegerv@8
1>GLFW.lib(glext.obj) : error LNK2019: unresolved external symbol __imp__glGetString@4 referenced in function __glfwParseGLVersion
1>c:\users\andrew\documents\visual studio 2010\Projects\glfwTest\Debug\glfwTest.exe : fatal error LNK1120: 9 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

最初のいくつかはランダムな色で理解できますが、それ以降は意味がわかりません。何が間違っているのか分かりますか?

ライブラリを正しくリンクしたと確信しています。ライブラリを C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib ディレクトリに配置し、さらに C:\SDK\GLFW\glfw-2.7.bin.WIN32\lib-msvc100\debug ディレクトリにリンクしました。

GLFW パッケージは .zip ファイルなので、デフォルトの SDK フォルダー (すべての API とその他のもの) に解凍しました。つまり、C:\SDK\GLFW が GLFW のデフォルトになります。

ベストアンサー1

にリンクする必要がありますopengl32.lib

そのためには、下図のように、 に移動してProject SettingLinker > input > Additional Dependenciesそこに追加しますopengl32.lib(;異なるライブラリを分離するために使用します)。

実際にファイルをどこかに置く必要はないことに注意してくださいopengl32.lib。Visual Studio は、そのファイルがどこにあるかを認識しています。

Visual Studio での追加ライブラリへのリンク

編集: を追加する以外は何もする必要がないことに注意してくださいopengl32.lib。その他のことは無関係です。さらに、両方が存在する場合は、順序を入れ替えてみてください。場合によってはこれが重要になります。

おすすめ記事