OpenGL GLFW构建错误或链接错误 [英] OpenGL GLFW build errors OR linking errors

查看:1231
本文介绍了OpenGL GLFW构建错误或链接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我获得GLFW在Visual Studio 2012中工作吗?我不能得到过去的初始编译。我不断得到未解决的外部GLFW功能。问题是,我不知道我做错了什么。我可以是:




  • 不正确地使用CMake创建源文件。

  • 不正确地构建库。

  • 不正确地链接到GLFW库。



是,所以我只列出我做了什么:

  1。从glfw.org下载glfw-3.1.1。 
2.使用CMake GUI制作源文件。
a。将源代码设置为C:/GLFW/glfw-3.1.1
b。将在哪里构建二进制文件设置为C:/GLFW/glfw-3.1.1/GLFW_Built(我创建了该目录)
c。点击配置
d。选择Visual Studio 11 2012作为生成器(我也试过Visual Studio 11 2012 Win64,但它给了我相同的结果,ARM一个不会构建)
e。左键选择使用默认本地编译器。
f。点击完成。
g。将BUILD_SHARED_LIBS设置为true(选中)。
h。点击生成。
3.构建库。
a到C:\GLFW\glfw-3.1.1\GLFW_Built并在Visual Studio 2012.中打开GLFW.sln。
b。点击BUILD-> Build ALL_BUILD(工作正常,没有错误)
4.在Visual Studio 2012中创建一个新的空白项目。
5.进入属性页面并设置:
a。配置属性/ VC ++目录/包含目录:添加C:\GLFW\glfw-3.1.1\include
b。配置属性/ VC ++目录/库目录:添加C:\GLFW\glfw-3.1.1\GLFW_Built\CMakeFiles\Export\lib(它是我看到的唯一lib文件夹)和C: \GLFW\glfw-3.1.1\GLFW_Built\src\Debug(包含glfw3.dll和glfw3dll.lib)
c。配置属性/ C / C ++ /其他包括目录:添加C:\GLFW\glfw-3.1.1\include
d。配置属性/链接器/常规:添加C:\GLFW\glfw-3.1.1\GLFW_Built\src\Debug
e。配置属性/链接器/输入:添加glfw3dll.lib 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:未解析的外部符号_glfwInit在函数_main中引用
1> main.obj:error LNK2019:unresolved外部符号_glfwTerminate在函数_main中引用
1> C:\Users\Adam\Desktop\Revenant\Revenant\Debug\Revenant.exe:致命错误LNK1120:2未解析的外部

将GLFW解压缩到 C:\glfw- src (这样存档中的 CMakeLists.txt 位于 C:\glfw-src\CMakeLists.txt




  • cd C:\glfw-src

  • mkdir build

  • cd build

  • cmake-gui ../

  • 按配置,选择toolchain

  • CMAKE_INSTALL_PREFIX 设为 C:/ glfw

  • 创建 c:\glfw 目录

  • 再次按配置

  • 生成

  • 在Visual Studio中打开 build\GLFW.sln

  • ALL_BUILD项目

  • 构建INSTALL项目的发行版



C:\glfw 现在应包含 include lib 目录。 p>

假设全新的空项目解决方案:




  • 编译器: code> c:\glfw\include / I (配置属性 - > C / C ++ - >常规 - >附加包括目录)

  • 链接器:将 c:\glfw\lib 添加到 / LIBPATH (配置属性 - >链接器 - >常规 - >附加库目录)并添加 glfw3.lib & opengl32.lib / DYNAMICBASE (配置属性 - >链接器 - >输入 - >其他依赖关系)


Can someone help me get GLFW working in Visual Studio 2012? I can't get past initial compilation. I keep getting unresolved externals for the GLFW functions. The problem is, I don't know what I'm doing wrong. I could be:

  • Improperly making the source files with CMake.
  • Improperly building the library.
  • Improperly linking to the GLFW library.

I'm not sure which of these it is, so I'll just list what I did:

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"

For my code, I just have a very simple test program in main.cpp:

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

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

But I always get this in the output:

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

解决方案

Extract GLFW to C:\glfw-src (such that CMakeLists.txt in the archive is at C:\glfw-src\CMakeLists.txt)

  • cd C:\glfw-src
  • mkdir build
  • cd build
  • cmake-gui ../
  • Press Configure, select toolchain
  • Set CMAKE_INSTALL_PREFIX to C:/glfw
  • Create c:\glfw directory
  • Press Configure again
  • Press Generate
  • Open build\GLFW.sln in Visual Studio
  • Build the Release version of the ALL_BUILD project
  • Build the Release version of the INSTALL project

C:\glfw should now contain include and lib directories.

Assuming a brand-new "Empty Project" solution:

  • Compiler: Add c:\glfw\include to /I (Configuration Properties -> C/C++ -> General -> Additional Include Directories)
  • Linker: Add c:\glfw\lib to /LIBPATH (Configuration Properties -> Linker -> General -> Additional Library Directories) and add glfw3.lib & opengl32.lib to /DYNAMICBASE (Configuration Properties -> Linker -> Input -> Additional Dependencies)

这篇关于OpenGL GLFW构建错误或链接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆