1b877906bSopenharmony_ci# Building applications {#build_guide}
2b877906bSopenharmony_ci
3b877906bSopenharmony_ci[TOC]
4b877906bSopenharmony_ci
5b877906bSopenharmony_ciThis is about compiling and linking applications that use GLFW.  For information on
6b877906bSopenharmony_cihow to write such applications, start with the
7b877906bSopenharmony_ci[introductory tutorial](@ref quick_guide).  For information on how to compile
8b877906bSopenharmony_cithe GLFW library itself, see @ref compile_guide.
9b877906bSopenharmony_ci
10b877906bSopenharmony_ciThis is not a tutorial on compilation or linking.  It assumes basic
11b877906bSopenharmony_ciunderstanding of how to compile and link a C program as well as how to use the
12b877906bSopenharmony_cispecific compiler of your chosen development environment.  The compilation
13b877906bSopenharmony_ciand linking process should be explained in your C programming material and in
14b877906bSopenharmony_cithe documentation for your development environment.
15b877906bSopenharmony_ci
16b877906bSopenharmony_ci
17b877906bSopenharmony_ci## Including the GLFW header file {#build_include}
18b877906bSopenharmony_ci
19b877906bSopenharmony_ciYou should include the GLFW header in the source files where you use OpenGL or
20b877906bSopenharmony_ciGLFW.
21b877906bSopenharmony_ci
22b877906bSopenharmony_ci```c
23b877906bSopenharmony_ci#include <GLFW/glfw3.h>
24b877906bSopenharmony_ci```
25b877906bSopenharmony_ci
26b877906bSopenharmony_ciThis header defines all the constants and declares all the types and function
27b877906bSopenharmony_ciprototypes of the GLFW API.  By default, it also includes the OpenGL header from
28b877906bSopenharmony_ciyour development environment.  See [option macros](@ref build_macros) below for
29b877906bSopenharmony_cihow to select OpenGL ES headers and more.
30b877906bSopenharmony_ci
31b877906bSopenharmony_ciThe GLFW header also defines any platform-specific macros needed by your OpenGL
32b877906bSopenharmony_ciheader, so that it can be included without needing any window system headers.
33b877906bSopenharmony_ci
34b877906bSopenharmony_ciIt does this only when needed, so if window system headers are included, the
35b877906bSopenharmony_ciGLFW header does not try to redefine those symbols.  The reverse is not true,
36b877906bSopenharmony_cii.e. `windows.h` cannot cope if any Win32 symbols have already been defined.
37b877906bSopenharmony_ci
38b877906bSopenharmony_ciIn other words:
39b877906bSopenharmony_ci
40b877906bSopenharmony_ci - Use the GLFW header to include OpenGL or OpenGL ES headers portably
41b877906bSopenharmony_ci - Do not include window system headers unless you will use those APIs directly
42b877906bSopenharmony_ci - If you do need such headers, include them before the GLFW header
43b877906bSopenharmony_ci
44b877906bSopenharmony_ciIf you are using an OpenGL extension loading library such as [glad][], the
45b877906bSopenharmony_ciextension loader header should be included before the GLFW one.  GLFW attempts
46b877906bSopenharmony_cito detect any OpenGL or OpenGL ES header or extension loader header included
47b877906bSopenharmony_cibefore it and will then disable the inclusion of the default OpenGL header.
48b877906bSopenharmony_ciMost extension loaders also define macros that disable similar headers below it.
49b877906bSopenharmony_ci
50b877906bSopenharmony_ci[glad]: https://github.com/Dav1dde/glad
51b877906bSopenharmony_ci
52b877906bSopenharmony_ci```c
53b877906bSopenharmony_ci#include <glad/gl.h>
54b877906bSopenharmony_ci#include <GLFW/glfw3.h>
55b877906bSopenharmony_ci```
56b877906bSopenharmony_ci
57b877906bSopenharmony_ciBoth of these mechanisms depend on the extension loader header defining a known
58b877906bSopenharmony_cimacro.  If yours doesn't or you don't know which one your users will pick, the
59b877906bSopenharmony_ci@ref GLFW_INCLUDE_NONE macro will explicitly prevent the GLFW header from
60b877906bSopenharmony_ciincluding the OpenGL header.  This will also allow you to include the two
61b877906bSopenharmony_ciheaders in any order.
62b877906bSopenharmony_ci
63b877906bSopenharmony_ci```c
64b877906bSopenharmony_ci#define GLFW_INCLUDE_NONE
65b877906bSopenharmony_ci#include <GLFW/glfw3.h>
66b877906bSopenharmony_ci#include <glad/gl.h>
67b877906bSopenharmony_ci```
68b877906bSopenharmony_ci
69b877906bSopenharmony_ci
70b877906bSopenharmony_ci### GLFW header option macros {#build_macros}
71b877906bSopenharmony_ci
72b877906bSopenharmony_ciThese macros may be defined before the inclusion of the GLFW header and affect
73b877906bSopenharmony_ciits behavior.
74b877906bSopenharmony_ci
75b877906bSopenharmony_ci@anchor GLFW_DLL
76b877906bSopenharmony_ci__GLFW_DLL__ is required on Windows when using the GLFW DLL, to tell the
77b877906bSopenharmony_cicompiler that the GLFW functions are defined in a DLL.
78b877906bSopenharmony_ci
79b877906bSopenharmony_ciThe following macros control which OpenGL or OpenGL ES API header is included.
80b877906bSopenharmony_ciOnly one of these may be defined at a time.
81b877906bSopenharmony_ci
82b877906bSopenharmony_ci@note GLFW does not provide any of the API headers mentioned below.  They are
83b877906bSopenharmony_ciprovided by your development environment or your OpenGL, OpenGL ES or Vulkan
84b877906bSopenharmony_ciSDK, and most of them can be downloaded from the [Khronos Registry][registry].
85b877906bSopenharmony_ci
86b877906bSopenharmony_ci[registry]: https://www.khronos.org/registry/
87b877906bSopenharmony_ci
88b877906bSopenharmony_ci@anchor GLFW_INCLUDE_GLCOREARB
89b877906bSopenharmony_ci__GLFW_INCLUDE_GLCOREARB__ makes the GLFW header include the modern
90b877906bSopenharmony_ci`GL/glcorearb.h` header (`OpenGL/gl3.h` on macOS) instead of the regular OpenGL
91b877906bSopenharmony_ciheader.
92b877906bSopenharmony_ci
93b877906bSopenharmony_ci@anchor GLFW_INCLUDE_ES1
94b877906bSopenharmony_ci__GLFW_INCLUDE_ES1__ makes the GLFW header include the OpenGL ES 1.x `GLES/gl.h`
95b877906bSopenharmony_ciheader instead of the regular OpenGL header.
96b877906bSopenharmony_ci
97b877906bSopenharmony_ci@anchor GLFW_INCLUDE_ES2
98b877906bSopenharmony_ci__GLFW_INCLUDE_ES2__ makes the GLFW header include the OpenGL ES 2.0
99b877906bSopenharmony_ci`GLES2/gl2.h` header instead of the regular OpenGL header.
100b877906bSopenharmony_ci
101b877906bSopenharmony_ci@anchor GLFW_INCLUDE_ES3
102b877906bSopenharmony_ci__GLFW_INCLUDE_ES3__ makes the GLFW header include the OpenGL ES 3.0
103b877906bSopenharmony_ci`GLES3/gl3.h` header instead of the regular OpenGL header.
104b877906bSopenharmony_ci
105b877906bSopenharmony_ci@anchor GLFW_INCLUDE_ES31
106b877906bSopenharmony_ci__GLFW_INCLUDE_ES31__ makes the GLFW header include the OpenGL ES 3.1
107b877906bSopenharmony_ci`GLES3/gl31.h` header instead of the regular OpenGL header.
108b877906bSopenharmony_ci
109b877906bSopenharmony_ci@anchor GLFW_INCLUDE_ES32
110b877906bSopenharmony_ci__GLFW_INCLUDE_ES32__ makes the GLFW header include the OpenGL ES 3.2
111b877906bSopenharmony_ci`GLES3/gl32.h` header instead of the regular OpenGL header.
112b877906bSopenharmony_ci
113b877906bSopenharmony_ci@anchor GLFW_INCLUDE_NONE
114b877906bSopenharmony_ci__GLFW_INCLUDE_NONE__ makes the GLFW header not include any OpenGL or OpenGL ES
115b877906bSopenharmony_ciAPI header.  This is useful in combination with an extension loading library.
116b877906bSopenharmony_ci
117b877906bSopenharmony_ciIf none of the above inclusion macros are defined, the standard OpenGL `GL/gl.h`
118b877906bSopenharmony_ciheader (`OpenGL/gl.h` on macOS) is included, unless GLFW detects the inclusion
119b877906bSopenharmony_ciguards of any OpenGL, OpenGL ES or extension loader header it knows about.
120b877906bSopenharmony_ci
121b877906bSopenharmony_ciThe following macros control the inclusion of additional API headers.  Any
122b877906bSopenharmony_cinumber of these may be defined simultaneously, and/or together with one of the
123b877906bSopenharmony_ciabove macros.
124b877906bSopenharmony_ci
125b877906bSopenharmony_ci@anchor GLFW_INCLUDE_VULKAN
126b877906bSopenharmony_ci__GLFW_INCLUDE_VULKAN__ makes the GLFW header include the Vulkan
127b877906bSopenharmony_ci`vulkan/vulkan.h` header in addition to any selected OpenGL or OpenGL ES header.
128b877906bSopenharmony_ci
129b877906bSopenharmony_ci@anchor GLFW_INCLUDE_GLEXT
130b877906bSopenharmony_ci__GLFW_INCLUDE_GLEXT__ makes the GLFW header include the appropriate extension
131b877906bSopenharmony_ciheader for the OpenGL or OpenGL ES header selected above after and in addition
132b877906bSopenharmony_cito that header.
133b877906bSopenharmony_ci
134b877906bSopenharmony_ci@anchor GLFW_INCLUDE_GLU
135b877906bSopenharmony_ci__GLFW_INCLUDE_GLU__ makes the header include the GLU header in addition to the
136b877906bSopenharmony_ciheader selected above.  This should only be used with the standard OpenGL header
137b877906bSopenharmony_ciand only for compatibility with legacy code.  GLU has been deprecated and should
138b877906bSopenharmony_cinot be used in new code.
139b877906bSopenharmony_ci
140b877906bSopenharmony_ci@note None of these macros may be defined during the compilation of GLFW itself.
141b877906bSopenharmony_ciIf your build includes GLFW and you define any these in your build files, make
142b877906bSopenharmony_cisure they are not applied to the GLFW sources.
143b877906bSopenharmony_ci
144b877906bSopenharmony_ci
145b877906bSopenharmony_ci## Link with the right libraries {#build_link}
146b877906bSopenharmony_ci
147b877906bSopenharmony_ciGLFW is essentially a wrapper of various platform-specific APIs and therefore
148b877906bSopenharmony_cineeds to link against many different system libraries.  If you are using GLFW as
149b877906bSopenharmony_cia shared library / dynamic library / DLL then it takes care of these links.
150b877906bSopenharmony_ciHowever, if you are using GLFW as a static library then your executable will
151b877906bSopenharmony_cineed to link against these libraries.
152b877906bSopenharmony_ci
153b877906bSopenharmony_ciOn Windows and macOS, the list of system libraries is static and can be
154b877906bSopenharmony_cihard-coded into your build environment.  See the section for your development
155b877906bSopenharmony_cienvironment below.  On Linux and other Unix-like operating systems, the list
156b877906bSopenharmony_civaries but can be retrieved in various ways as described below.
157b877906bSopenharmony_ci
158b877906bSopenharmony_ciA good general introduction to linking is [Beginner's Guide to
159b877906bSopenharmony_ciLinkers][linker_guide] by David Drysdale.
160b877906bSopenharmony_ci
161b877906bSopenharmony_ci[linker_guide]: https://www.lurklurk.org/linkers/linkers.html
162b877906bSopenharmony_ci
163b877906bSopenharmony_ci
164b877906bSopenharmony_ci### With Visual C++ and GLFW binaries {#build_link_win32}
165b877906bSopenharmony_ci
166b877906bSopenharmony_ciIf you are using a downloaded [binary
167b877906bSopenharmony_ciarchive](https://www.glfw.org/download.html), first make sure you have the
168b877906bSopenharmony_ciarchive matching the architecture you are building for (32-bit or 64-bit), or
169b877906bSopenharmony_ciyou will get link errors.  Also make sure you are using the binaries for your
170b877906bSopenharmony_civersion of Visual C++ or you may get other link errors.
171b877906bSopenharmony_ci
172b877906bSopenharmony_ciThere are two version of the static GLFW library in the binary archive, because
173b877906bSopenharmony_ciit needs to use the same base run-time library variant as the rest of your
174b877906bSopenharmony_ciexecutable.
175b877906bSopenharmony_ci
176b877906bSopenharmony_ciOne is named `glfw3.lib` and is for projects with the _Runtime Library_ project
177b877906bSopenharmony_cioption set to _Multi-threaded DLL_ or _Multi-threaded Debug DLL_.  The other is
178b877906bSopenharmony_cinamed `glfw3_mt.lib` and is for projects with _Runtime Library_ set to
179b877906bSopenharmony_ci_Multi-threaded_ or _Multi-threaded Debug_.  To use the static GLFW library you
180b877906bSopenharmony_ciwill need to add `path/to/glfw3.lib` or `path/to/glfw3_mt.lib` to the
181b877906bSopenharmony_ci_Additional Dependencies_ project option.
182b877906bSopenharmony_ci
183b877906bSopenharmony_ciIf you compiled a GLFW static library yourself then there will only be one,
184b877906bSopenharmony_cinamed `glfw3.lib`, and you have to make sure the run-time library variant
185b877906bSopenharmony_cimatches.
186b877906bSopenharmony_ci
187b877906bSopenharmony_ciThe DLL version of the GLFW library is named `glfw3.dll`, but you will be
188b877906bSopenharmony_cilinking against the `glfw3dll.lib` link library.  To use the DLL you will need
189b877906bSopenharmony_cito add `path/to/glfw3dll.lib` to the _Additional Dependencies_ project option.
190b877906bSopenharmony_ciAll of its dependencies are already listed there by default, but when building
191b877906bSopenharmony_ciwith the DLL version of GLFW, you also need to define the @ref GLFW_DLL.  This
192b877906bSopenharmony_cican be done either in the _Preprocessor Definitions_ project option or by
193b877906bSopenharmony_cidefining it in your source code before including the GLFW header.
194b877906bSopenharmony_ci
195b877906bSopenharmony_ci```c
196b877906bSopenharmony_ci#define GLFW_DLL
197b877906bSopenharmony_ci#include <GLFW/glfw3.h>
198b877906bSopenharmony_ci```
199b877906bSopenharmony_ci
200b877906bSopenharmony_ciAll link-time dependencies for GLFW are already listed in the _Additional
201b877906bSopenharmony_ciDependencies_ option by default.
202b877906bSopenharmony_ci
203b877906bSopenharmony_ci
204b877906bSopenharmony_ci### With MinGW-w64 and GLFW binaries {#build_link_mingw}
205b877906bSopenharmony_ci
206b877906bSopenharmony_ciThis is intended for building a program from the command-line or by writing
207b877906bSopenharmony_cia makefile, on Windows with [MinGW-w64][] and GLFW binaries.  These can be from
208b877906bSopenharmony_cia downloaded and extracted [binary archive](https://www.glfw.org/download.html)
209b877906bSopenharmony_cior by compiling GLFW yourself.  The paths below assume a binary archive is used.
210b877906bSopenharmony_ci
211b877906bSopenharmony_ciIf you are using a downloaded binary archive, first make sure you have the
212b877906bSopenharmony_ciarchive matching the architecture you are building for (32-bit or 64-bit) or you
213b877906bSopenharmony_ciwill get link errors.
214b877906bSopenharmony_ci
215b877906bSopenharmony_ciNote that the order of source files and libraries matter for GCC.  Dependencies
216b877906bSopenharmony_cimust be listed after the files that depend on them.  Any source files that
217b877906bSopenharmony_cidepend on GLFW must be listed before the GLFW library.  GLFW in turn depends on
218b877906bSopenharmony_ci`gdi32` and must be listed before it.
219b877906bSopenharmony_ci
220b877906bSopenharmony_ci[MinGW-w64]: https://www.mingw-w64.org/
221b877906bSopenharmony_ci
222b877906bSopenharmony_ciIf you are using the static version of the GLFW library, which is named
223b877906bSopenharmony_ci`libglfw3.a`, do:
224b877906bSopenharmony_ci
225b877906bSopenharmony_ci```sh
226b877906bSopenharmony_cigcc -o myprog myprog.c -I path/to/glfw/include path/to/glfw/lib-mingw-w64/libglfw3.a -lgdi32
227b877906bSopenharmony_ci```
228b877906bSopenharmony_ci
229b877906bSopenharmony_ciIf you are using the DLL version of the GLFW library, which is named
230b877906bSopenharmony_ci`glfw3.dll`, you will need to use the `libglfw3dll.a` link library.
231b877906bSopenharmony_ci
232b877906bSopenharmony_ci```sh
233b877906bSopenharmony_cigcc -o myprog myprog.c -I path/to/glfw/include path/to/glfw/lib-mingw-w64/libglfw3dll.a -lgdi32
234b877906bSopenharmony_ci```
235b877906bSopenharmony_ci
236b877906bSopenharmony_ciThe resulting executable will need to find `glfw3.dll` to run, typically by
237b877906bSopenharmony_cikeeping both files in the same directory.
238b877906bSopenharmony_ci
239b877906bSopenharmony_ciWhen you are building with the DLL version of GLFW, you will also need to define
240b877906bSopenharmony_cithe @ref GLFW_DLL macro.  This can be done in your source files, as long as it
241b877906bSopenharmony_cidone before including the GLFW header:
242b877906bSopenharmony_ci
243b877906bSopenharmony_ci```c
244b877906bSopenharmony_ci#define GLFW_DLL
245b877906bSopenharmony_ci#include <GLFW/glfw3.h>
246b877906bSopenharmony_ci```
247b877906bSopenharmony_ci
248b877906bSopenharmony_ciIt can also be done on the command-line:
249b877906bSopenharmony_ci
250b877906bSopenharmony_ci```sh
251b877906bSopenharmony_cigcc -o myprog myprog.c -D GLFW_DLL -I path/to/glfw/include path/to/glfw/lib-mingw-w64/libglfw3dll.a -lgdi32
252b877906bSopenharmony_ci```
253b877906bSopenharmony_ci
254b877906bSopenharmony_ci
255b877906bSopenharmony_ci### With CMake and GLFW source {#build_link_cmake_source}
256b877906bSopenharmony_ci
257b877906bSopenharmony_ciThis section is about using CMake to compile and link GLFW along with your
258b877906bSopenharmony_ciapplication.  If you want to use an installed binary instead, see @ref
259b877906bSopenharmony_cibuild_link_cmake_package.
260b877906bSopenharmony_ci
261b877906bSopenharmony_ciWith a few changes to your `CMakeLists.txt` you can have the GLFW source tree
262b877906bSopenharmony_cibuilt along with your application.
263b877906bSopenharmony_ci
264b877906bSopenharmony_ciAdd the root directory of the GLFW source tree to your project.  This will add
265b877906bSopenharmony_cithe `glfw` target to your project.
266b877906bSopenharmony_ci
267b877906bSopenharmony_ci```cmake
268b877906bSopenharmony_ciadd_subdirectory(path/to/glfw)
269b877906bSopenharmony_ci```
270b877906bSopenharmony_ci
271b877906bSopenharmony_ciOnce GLFW has been added, link your application against the `glfw` target.
272b877906bSopenharmony_ciThis adds the GLFW library and its link-time dependencies as it is currently
273b877906bSopenharmony_ciconfigured, the include directory for the GLFW header and, when applicable, the
274b877906bSopenharmony_ci@ref GLFW_DLL macro.
275b877906bSopenharmony_ci
276b877906bSopenharmony_ci```cmake
277b877906bSopenharmony_citarget_link_libraries(myapp glfw)
278b877906bSopenharmony_ci```
279b877906bSopenharmony_ci
280b877906bSopenharmony_ciNote that the `glfw` target does not depend on OpenGL, as GLFW loads any OpenGL,
281b877906bSopenharmony_ciOpenGL ES or Vulkan libraries it needs at runtime.  If your application calls
282b877906bSopenharmony_ciOpenGL directly, instead of using a modern
283b877906bSopenharmony_ci[extension loader library](@ref context_glext_auto), use the OpenGL CMake
284b877906bSopenharmony_cipackage.
285b877906bSopenharmony_ci
286b877906bSopenharmony_ci```cmake
287b877906bSopenharmony_cifind_package(OpenGL REQUIRED)
288b877906bSopenharmony_ci```
289b877906bSopenharmony_ci
290b877906bSopenharmony_ciIf OpenGL is found, the `OpenGL::GL` target is added to your project, containing
291b877906bSopenharmony_cilibrary and include directory paths.  Link against this like any other library.
292b877906bSopenharmony_ci
293b877906bSopenharmony_ci```cmake
294b877906bSopenharmony_citarget_link_libraries(myapp OpenGL::GL)
295b877906bSopenharmony_ci```
296b877906bSopenharmony_ci
297b877906bSopenharmony_ciFor a minimal example of a program and GLFW sources built with CMake, see the
298b877906bSopenharmony_ci[GLFW CMake Starter][cmake_starter] on GitHub.
299b877906bSopenharmony_ci
300b877906bSopenharmony_ci[cmake_starter]: https://github.com/juliettef/GLFW-CMake-starter
301b877906bSopenharmony_ci
302b877906bSopenharmony_ci
303b877906bSopenharmony_ci### With CMake and installed GLFW binaries {#build_link_cmake_package}
304b877906bSopenharmony_ci
305b877906bSopenharmony_ciThis section is about using CMake to link GLFW after it has been built and
306b877906bSopenharmony_ciinstalled.  If you want to build it along with your application instead, see
307b877906bSopenharmony_ci@ref build_link_cmake_source.
308b877906bSopenharmony_ci
309b877906bSopenharmony_ciWith a few changes to your `CMakeLists.txt` you can locate the package and
310b877906bSopenharmony_citarget files generated when GLFW is installed.
311b877906bSopenharmony_ci
312b877906bSopenharmony_ci```cmake
313b877906bSopenharmony_cifind_package(glfw3 3.5 REQUIRED)
314b877906bSopenharmony_ci```
315b877906bSopenharmony_ci
316b877906bSopenharmony_ciOnce GLFW has been added to the project, link against it with the `glfw` target.
317b877906bSopenharmony_ciThis adds the GLFW library and its link-time dependencies, the include directory
318b877906bSopenharmony_cifor the GLFW header and, when applicable, the @ref GLFW_DLL macro.
319b877906bSopenharmony_ci
320b877906bSopenharmony_ci```cmake
321b877906bSopenharmony_citarget_link_libraries(myapp glfw)
322b877906bSopenharmony_ci```
323b877906bSopenharmony_ci
324b877906bSopenharmony_ciNote that the `glfw` target does not depend on OpenGL, as GLFW loads any OpenGL,
325b877906bSopenharmony_ciOpenGL ES or Vulkan libraries it needs at runtime.  If your application calls
326b877906bSopenharmony_ciOpenGL directly, instead of using a modern
327b877906bSopenharmony_ci[extension loader library](@ref context_glext_auto), use the OpenGL CMake
328b877906bSopenharmony_cipackage.
329b877906bSopenharmony_ci
330b877906bSopenharmony_ci```cmake
331b877906bSopenharmony_cifind_package(OpenGL REQUIRED)
332b877906bSopenharmony_ci```
333b877906bSopenharmony_ci
334b877906bSopenharmony_ciIf OpenGL is found, the `OpenGL::GL` target is added to your project, containing
335b877906bSopenharmony_cilibrary and include directory paths.  Link against this like any other library.
336b877906bSopenharmony_ci
337b877906bSopenharmony_ci```cmake
338b877906bSopenharmony_citarget_link_libraries(myapp OpenGL::GL)
339b877906bSopenharmony_ci```
340b877906bSopenharmony_ci
341b877906bSopenharmony_ci
342b877906bSopenharmony_ci### With pkg-config and GLFW binaries on Unix {#build_link_pkgconfig}
343b877906bSopenharmony_ci
344b877906bSopenharmony_ciThis is intended for building a program from the command-line or by writing
345b877906bSopenharmony_cia makefile, on macOS or any Unix-like system like Linux, FreeBSD and Cygwin.
346b877906bSopenharmony_ci
347b877906bSopenharmony_ciGLFW supports [pkg-config][], and the `glfw3.pc` pkg-config file is generated
348b877906bSopenharmony_ciwhen the GLFW library is built and is installed along with it.  A pkg-config
349b877906bSopenharmony_cifile describes all necessary compile-time and link-time flags and dependencies
350b877906bSopenharmony_cineeded to use a library.  When they are updated or if they differ between
351b877906bSopenharmony_cisystems, you will get the correct ones automatically.
352b877906bSopenharmony_ci
353b877906bSopenharmony_ci[pkg-config]: https://www.freedesktop.org/wiki/Software/pkg-config/
354b877906bSopenharmony_ci
355b877906bSopenharmony_ciA typical compile and link command-line when using the static version of the
356b877906bSopenharmony_ciGLFW library may look like this:
357b877906bSopenharmony_ci
358b877906bSopenharmony_ci```sh
359b877906bSopenharmony_cicc $(pkg-config --cflags glfw3) -o myprog myprog.c $(pkg-config --static --libs glfw3)
360b877906bSopenharmony_ci```
361b877906bSopenharmony_ci
362b877906bSopenharmony_ciIf you are using the shared version of the GLFW library, omit the `--static`
363b877906bSopenharmony_ciflag.
364b877906bSopenharmony_ci
365b877906bSopenharmony_ci```sh
366b877906bSopenharmony_cicc $(pkg-config --cflags glfw3) -o myprog myprog.c $(pkg-config --libs glfw3)
367b877906bSopenharmony_ci```
368b877906bSopenharmony_ci
369b877906bSopenharmony_ciYou can also use the `glfw3.pc` file without installing it first, by using the
370b877906bSopenharmony_ci`PKG_CONFIG_PATH` environment variable.
371b877906bSopenharmony_ci
372b877906bSopenharmony_ci```sh
373b877906bSopenharmony_cienv PKG_CONFIG_PATH=path/to/glfw/src cc $(pkg-config --cflags glfw3) -o myprog myprog.c $(pkg-config --libs glfw3)
374b877906bSopenharmony_ci```
375b877906bSopenharmony_ci
376b877906bSopenharmony_ciThe dependencies do not include OpenGL, as GLFW loads any OpenGL, OpenGL ES or
377b877906bSopenharmony_ciVulkan libraries it needs at runtime.  If your application calls OpenGL
378b877906bSopenharmony_cidirectly, instead of using a modern
379b877906bSopenharmony_ci[extension loader library](@ref context_glext_auto), you should add the `gl`
380b877906bSopenharmony_cipkg-config package.
381b877906bSopenharmony_ci
382b877906bSopenharmony_ci```sh
383b877906bSopenharmony_cicc $(pkg-config --cflags glfw3 gl) -o myprog myprog.c $(pkg-config --libs glfw3 gl)
384b877906bSopenharmony_ci```
385b877906bSopenharmony_ci
386b877906bSopenharmony_ci
387b877906bSopenharmony_ci### With Xcode on macOS {#build_link_xcode}
388b877906bSopenharmony_ci
389b877906bSopenharmony_ciIf you are using the dynamic library version of GLFW, add it to the project
390b877906bSopenharmony_cidependencies.
391b877906bSopenharmony_ci
392b877906bSopenharmony_ciIf you are using the static library version of GLFW, add it and the Cocoa,
393b877906bSopenharmony_ciOpenGL, IOKit and QuartzCore frameworks to the project as dependencies.  They
394b877906bSopenharmony_cican all be found in `/System/Library/Frameworks`.
395b877906bSopenharmony_ci
396b877906bSopenharmony_ci
397b877906bSopenharmony_ci### With command-line or makefile on macOS {#build_link_osx}
398b877906bSopenharmony_ci
399b877906bSopenharmony_ciIt is recommended that you use [pkg-config](@ref build_link_pkgconfig) when
400b877906bSopenharmony_ciusing installed GLFW binaries from the command line on macOS.  That way you will
401b877906bSopenharmony_ciget any new dependencies added automatically.  If you still wish to build
402b877906bSopenharmony_cimanually, you need to add the required frameworks and libraries to your
403b877906bSopenharmony_cicommand-line yourself using the `-l` and `-framework` switches.
404b877906bSopenharmony_ci
405b877906bSopenharmony_ciIf you are using the dynamic GLFW library, which is named `libglfw.3.dylib`, do:
406b877906bSopenharmony_ci
407b877906bSopenharmony_ci```sh
408b877906bSopenharmony_cicc -o myprog myprog.c -lglfw -framework Cocoa -framework OpenGL -framework IOKit -framework QuartzCore
409b877906bSopenharmony_ci```
410b877906bSopenharmony_ci
411b877906bSopenharmony_ciIf you are using the static library, named `libglfw3.a`, substitute `-lglfw3`
412b877906bSopenharmony_cifor `-lglfw`.
413b877906bSopenharmony_ci
414b877906bSopenharmony_ciNote that you do not add the `.framework` extension to a framework when linking
415b877906bSopenharmony_ciagainst it from the command-line.
416b877906bSopenharmony_ci
417b877906bSopenharmony_ci@note Your machine may have `libGL.*.dylib` style OpenGL library, but that is
418b877906bSopenharmony_cifor the X Window System and will not work with the macOS native version of GLFW.
419b877906bSopenharmony_ci
420