OpenGL GLFW构建错误或链接错误

时间:2015-05-24 03:53:03

标签: c++ opengl visual-studio-2012 glfw cmake-gui

有人可以帮我在Visual Studio 2012中使用GLFW吗?我无法通过初始编译。我一直在为GLFW功能获得未解决的外部因素。问题是,我不知道我做错了什么。我可以:

  • 使用CMake不正确地制作源文件。
  • 不正确地建立图书馆。
  • 错误地链接到GLFW库。

我不确定它是哪一个,所以我只列出我的所作所为:

1. Downloaded glfw-3.1.1 from glfw.org.
2. Used CMake GUI to make the source files.
    a. Set source code to C:/GLFW/glfw-3.1.1
    b. Set "Where to build the binaries" to C:/GLFW/glfw-3.1.1/GLFW_Built (I created that directory)
    c. Clicked "Configure" 
    d. Selected "Visual Studio 11 2012" as the generator (I also tried "Visual Studio 11 2012 Win64," but it gave me the same results. The ARM one wouldn't build at all)
    e. Left "Use default native compilers" selected.
    f. Clicked "Finish."
    g. Set "BUILD_SHARED_LIBS" to true (checked).
    h. Clicked "Generate."
3. Built the library.
    a. Went to C:\GLFW\glfw-3.1.1\GLFW_Built and opened GLFW.sln in Visual Studio 2012.
    b. Clicked BUILD->Build ALL_BUILD (worked fine, no errors)
4. Created a new blank project in Visual Studio 2012.
5. Went into the properties pages and set:
    a. Configuration Properties/VC++ Directories/Include Directories: added "C:\GLFW\glfw-3.1.1\include"
    b. Configuration Properties/VC++ Directories/Library Directories: added "C:\GLFW\glfw-3.1.1\GLFW_Built\CMakeFiles\Export\lib" (it was the only lib folder I saw) and "C:\GLFW\glfw-3.1.1\GLFW_Built\src\Debug" (contains glfw3.dll and glfw3dll.lib)
    c. Configuration Properties/C/C++/Additional Include Directories: added "C:\GLFW\glfw-3.1.1\include"
    d. Configuration Properties/Linker/General: added "C:\GLFW\glfw-3.1.1\GLFW_Built\src\Debug
    e. Configuration Properties/Linker/Input: added "glfw3dll.lib" and "opengl32.lib"

对于我的代码,我在main.cpp中只有一个非常简单的测试程序:

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

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

但我总是在输出中得到这个:

1>main.obj : error LNK2019: unresolved external symbol _glfwInit referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _glfwTerminate referenced in function _main
1>C:\Users\Adam\Desktop\Revenant\Revenant\Debug\Revenant.exe : fatal error LNK1120: 2 unresolved externals

1 个答案:

答案 0 :(得分:1)

将GLFW提取到<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input id="authorities" name="authorities" type="text"> <button id="addEmail">Add e-mail</button> <input id="team_authority_emails" name="team[authority_emails]" type="hidden" value="{asvxcvxcvva@gmail.com,test@test.com.au}"> <!-- a div so you can see the result --> <div id="out"></div>(以使归档中的C:\glfw-src位于CMakeLists.txt

  • C:\glfw-src\CMakeLists.txt
  • cd C:\glfw-src
  • mkdir build
  • cd build
  • 按Configure,选择工具链
  • cmake-gui ../设为CMAKE_INSTALL_PREFIX
  • 创建C:/glfw目录
  • 再次按“配置”
  • 按生成
  • 在Visual Studio中打开c:\glfw
  • 构建ALL_BUILD项目的发布版本
  • 构建INSTALL项目的发布版本

build\GLFW.sln现在应包含C:\glfwinclude目录。

假设一个全新的#34;空项目&#34;溶液:

  • 编译器:将lib添加到c:\glfw\include(配置属性 - &gt; C / C ++ - &gt;常规 - &gt;其他包含目录)
  • 链接器:将/I添加到c:\glfw\lib(配置属性 - &gt;链接器 - &gt;常规 - &gt;其他库目录)并添加/LIBPATH&amp; glfw3.libopengl32.lib(配置属性 - &gt;链接器 - &gt;输入 - &gt;附加依赖项)