# Why i cant link Library and Header file

**URL:** <https://discourse.glfw.org/t/why-i-cant-link-library-and-header-file/2074>\
**Category:** support\
**Created:** [June 15, 2022, 2:23pm UTC](https://discourse.glfw.org/t/why-i-cant-link-library-and-header-file/2074 "2022-06-15T14:23:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![vitcon](https://avatars.discourse-cdn.com/v4/letter/v/58956e/32.png) [@vitcon](https://discourse.glfw.org/u/vitcon)\
**Post date:** [June 15, 2022, 2:23pm UTC](https://discourse.glfw.org/t/why-i-cant-link-library-and-header-file/2074/1 "2022-06-15T14:23:39Z")

</div>

![Screenshot from 2022-06-16 04-14-52](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/43d05700b7bb1faf446e8473a934ca7115a01419.png)

i have build on linux-debian.  
but failed when i run command-line. Can some teach me how to link Library and Header file rigth way?

---

<div class="post-metadata">

**Author:** ![vitcon](https://avatars.discourse-cdn.com/v4/letter/v/58956e/32.png) [@vitcon](https://discourse.glfw.org/u/vitcon)\
**Post date:** [June 15, 2022, 2:24pm UTC](https://discourse.glfw.org/t/why-i-cant-link-library-and-header-file/2074/2 "2022-06-15T14:24:59Z")

</div>

![Screenshot from 2022-06-16 04-15-37](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/36157fcc622ae6b8519847af14b2f58e7830f1e3.png)

---

<div class="post-metadata">

**Author:** ![vitcon](https://avatars.discourse-cdn.com/v4/letter/v/58956e/32.png) [@vitcon](https://discourse.glfw.org/u/vitcon)\
**Post date:** [June 15, 2022, 2:25pm UTC](https://discourse.glfw.org/t/why-i-cant-link-library-and-header-file/2074/3 "2022-06-15T14:25:30Z")

</div>

![Screenshot from 2022-06-16 04-15-50](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/5cc32e28fd7ca4d5474ed8d620714e21e6a5b809.png)

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [June 15, 2022, 3:25pm UTC](https://discourse.glfw.org/t/why-i-cant-link-library-and-header-file/2074/4 "2022-06-15T15:25:51Z")

</div>

Hi @vitcon,

welcome to the GLFW forum. The easiest to make a GLFW program would be with this GLFW Cmake Starter:

> **[GitHub - juliettef/GLFW-CMake-starter: Use CMake to create a project with GLFW...](https://github.com/juliettef/GLFW-CMake-starter)**
>
> Use CMake to create a project with GLFW - Multi-platform Windows, Linux and MacOS. - GitHub - juliettef/GLFW-CMake-starter: Use CMake to create a project with GLFW - Multi-platform Windows, Linux a...

The errors you are seeing are due to you not linking to the GLFW library, you need to add `-lglfw`. However after adding this you will likely get further errors due to needing to link to other libraries as well. You can use pkg-config to help configure the required compile-time and link-time flags and dependencies needed to use a library:  
[https://www.glfw.org/docs/latest/build\_guide.html#build\_link\_pkgconfig](https://www.glfw.org/docs/latest/build_guide.html#build_link_pkgconfig)

In future note that it’s easier for us if rather than attaching images you copy and paste the text from your console.

Good luck!

---

<div class="post-metadata">

**Author:** ![vitcon](https://avatars.discourse-cdn.com/v4/letter/v/58956e/32.png) [@vitcon](https://discourse.glfw.org/u/vitcon)\
**Post date:** [June 16, 2022, 1:09am UTC](https://discourse.glfw.org/t/why-i-cant-link-library-and-header-file/2074/5 "2022-06-16T01:09:34Z")

</div>

Thanks you very much. This very useful for me. 🥰

---

<div class="post-metadata">

**Author:** ![Papasot](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/papasot/32/192_2.png) [@Papasot](https://discourse.glfw.org/u/Papasot)\
**Post date:** [June 30, 2022, 10:03am UTC](https://discourse.glfw.org/t/why-i-cant-link-library-and-header-file/2074/6 "2022-06-30T10:03:27Z")

</div>

Linking errors like those are not necessarily because you omitted `-lglfw`, although this is what I would check first. Some linkers demand a specific way to link libraries, and the “correct” way may depend on the distribution you are using. For example, the “logical” way to link is `-lGL -lglfw` (first OpenGL, then GLFW) - and indeed it works just fine in most cases. However, I got linking errors like the ones you had on some Debian-based distributions, where `-lglfw -lGL` worked instead.

---

<div class="post-metadata">

**Author:** ![mmozeiko](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/mmozeiko/32/29_2.png) [@mmozeiko](https://discourse.glfw.org/u/mmozeiko)\
**Post date:** [June 30, 2022, 10:17am UTC](https://discourse.glfw.org/t/why-i-cant-link-library-and-header-file/2074/7 "2022-06-30T10:17:25Z")

</div>

You can always add `-Wl,--start-group` before libraries and `-Wl,--end-group` at end, then rest of them can go in the middle in any order, like this:

```auto
-Wl,--start-group -lGL -lglfw -Wl,--end-group

```
