0

我很难找到有关使用 Cygwin-g++ 编译基本 OpenGL/GLFW 示例 Windows 的文档,所以我决定发布我自己问题的答案。

  • 操作系统:Windows (10)
  • 编译器:Cygwin g++ (x86_64-pc-cygwin)
  • 代码:GLFW 文档的示例代码(基本工作示例如下所示。不会创建窗口,但如果一切都正确构建/链接,则应输出文本):

    #define GLFW_DLL
    #include <GLFW/glfw3.h>
    #include <iostream>
    
    int main(void) {
        std::cout << "Code works" << std::endl;
        if (!glfwInit())
            return -1;
        glfwTerminate();
        return 0;
    }

  • 汇编:g++ -Wall -Iinclude main.cpp -o main.exe -L<folder glfw3.dll is in> -lglfw3 -lopengl32 -lgdi32

问题

  • 代码将编译和构建,但不会出现输出窗口
  • 我当前的链接很好,但不同的组合会导致undefined reference错误。
4

2 回答 2

1

alternative solution building the GLFW for Cygwin

Download glfw-3.3.4.zip and then

$ unzip glfw-3.3.4.zip
$ cd glfw-3.3.4
$ ccmake .

set BUILD_SHARED_LIBS to ON. Configure and generate

$ make
$ make install

Install the project...
-- Install configuration: ""
-- Up-to-date: /usr/local/include/GLFW
-- Up-to-date: /usr/local/include/GLFW/glfw3.h
-- Up-to-date: /usr/local/include/GLFW/glfw3native.h
-- Up-to-date: /usr/local/lib/cmake/glfw3/glfw3Config.cmake
-- Up-to-date: /usr/local/lib/cmake/glfw3/glfw3ConfigVersion.cmake
-- Up-to-date: /usr/local/lib/cmake/glfw3/glfw3Targets.cmake
-- Up-to-date: /usr/local/lib/cmake/glfw3/glfw3Targets-noconfig.cmake
-- Up-to-date: /usr/local/lib/pkgconfig/glfw3.pc
-- Up-to-date: /usr/local/lib/libglfw.dll.a
-- Up-to-date: /usr/local/bin/cygglfw-3.dll

So you will have a proper Cygwin build installed under /usr/local
after that, running under X server

$ g++ main.cpp -o main -lglfw -L/usr/local/lib

$ ./main.exe 
Code works
于 2021-07-28T06:29:28.090 回答
0

这个答案是密歇根大学 EECS 487 building OpenGL/GLFW Apps解决方案的总结

安装验证 检查这些文件是否存在于 cygwin64 目录下。

  • 头文件:/usr/include/w32api/GL
  • 静态库:/lib/w32api/lib{opengl,gdi}32.a

安装 GLFW 二进制文件 GLFW 二进制文件

将 GLFW 二进制文件中的文件复制到 Cygwin

  • \cygwin64\usr\x86_64-pc-cygwin\GLFW 二进制文件中粘贴包含文件include。你应该有\cygwin64\usr\x86_64-pc-cygwin\include\GLFW里面的 .h 文件

  • C:\cygwin64\usr\x86_64-pc-cygwin\libGLFW 二进制文件的 lib-mingw-w64 文件夹中粘贴 libglfw3.a 和 libglfw3dll.a

  • 从上述文件夹\cygwin64\usr\x86_64-pc-cygwin\bin粘贴glfw3.dll

  • 添加\cygwin64\usr\x86_64-pc-cygwin\bin到路径

  • 编译g++ -Wall -Iinclude main.cpp -o main.exe -LC:\cygwin64\usr\x86_64-pc-cygwin\bin -lglfw3 -lopengl32 -lgdi32(将 -L 更改为 cygwin 的存储位置)。

ETC

  • 第一个链接包含使用 MingW 工具链以及 Linux、MacOS 和 Visual Studios 进行构建的说明
于 2021-07-27T16:10:08.647 回答