# I'm having trouble Linking glfw and glm

**URL:** https://discourse.cmake.org/t/im-having-trouble-linking-glfw-and-glm/9793
**Category:** Code
**Tags:** os:windows
**Created:** [January 7, 2024, 11:56am UTC](https://discourse.cmake.org/t/im-having-trouble-linking-glfw-and-glm/9793 "2024-01-07T11:56:28Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Greddode](https://discourse.cmake.org/user_avatar/discourse.cmake.org/greddode/32/4142_2.png) [@Greddode](https://discourse.cmake.org/u/Greddode)
#### Post date: [January 7, 2024, 11:56am UTC](https://discourse.cmake.org/t/im-having-trouble-linking-glfw-and-glm/9793/1 "2024-01-07T11:56:28Z")

</div>

I’m using VS to add in the Libraries of GLFW and GLM to my project. I’m very new but it gives me an error saying it’s not built.

CMake Error at C:\Users\patri\Documents\Game\_dev\Engines\EndBullet\CMakeLists.txt:42 (target\_link\_libraries):  
Attempt to add link library “glm” to target “Engine” which is not built  
in this directory.

---

<div class="post-metadata">

### Author: ![Greddode](https://discourse.cmake.org/user_avatar/discourse.cmake.org/greddode/32/4142_2.png) [@Greddode](https://discourse.cmake.org/u/Greddode)
#### Post date: [January 7, 2024, 11:57am UTC](https://discourse.cmake.org/t/im-having-trouble-linking-glfw-and-glm/9793/2 "2024-01-07T11:57:43Z")

</div>

The code

> **[\# CMakeList.txt : Top-level CMake project file, do global configuration# and i...](https://pastebin.com/mPxMzNM7)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

---

<div class="post-metadata">

### Author: ![Greddode](https://discourse.cmake.org/user_avatar/discourse.cmake.org/greddode/32/4142_2.png) [@Greddode](https://discourse.cmake.org/u/Greddode)
#### Post date: [January 7, 2024, 12:36pm UTC](https://discourse.cmake.org/t/im-having-trouble-linking-glfw-and-glm/9793/3 "2024-01-07T12:36:57Z")

</div>

cmake\_policy(SET CMP0079 NEW)  
Hsd to do this, what does this do?

---

<div class="post-metadata">

### Author: ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)
#### Post date: [January 7, 2024, 2:36pm UTC](https://discourse.cmake.org/t/im-having-trouble-linking-glfw-and-glm/9793/4 "2024-01-07T14:36:14Z")

</div>

> ```cmd
> Attempt to add link library "glm" to target "Engine" which is not built in this directory
> 
> ```

That is strange, because you have

```cmake
project("EndBullet")

```

and so in

```cmake
target_link_libraries("${CMAKE_PROJECT_NAME}" PRIVATE glm glfw)

```

the `${CMAKE_PROJECT_NAME}` should evaluate to `EndBullet`, not to `Engine`. It could be that one of the `CMakeLists.txt`’s in added sub-directories modifies this variable or something.

Also, from the only `CMakeLists.txt` file that you shared it seems that there is not a single target declared (_neither a library nor an executable_), which GLM and GLFW are supposed to be linked with.

---

<div class="post-metadata">

### Author: ![dnglaze](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/74df32/32.png) [@dnglaze](https://discourse.cmake.org/u/dnglaze)
#### Post date: [January 7, 2024, 6:01pm UTC](https://discourse.cmake.org/t/im-having-trouble-linking-glfw-and-glm/9793/5 "2024-01-07T18:01:53Z")

</div>

I’d recommend avoiding using the `CMAKE_PROJECT_NAME` variable and just use the target name directly. If you look at the docs for [`CMAKE_PROJECT_NAME`](https://cmake.org/cmake/help/latest/variable/CMAKE_PROJECT_NAME.html), pay attention to how it describes the variable’s behavior. You’re likely picking up the `Engine` project name from the top-level CMakeLists.txt that’s pulling in the one you’ve pasted. You likely are not creating a library named that and so the `target_link_libraries` is failing because the target doesn’t exist.

You may instead be meaning to use the [`PROJECT_NAME`](https://cmake.org/cmake/help/latest/variable/PROJECT_NAME.html#variable:PROJECT_NAME) variable which likely has the behavior you’re looking for since it picks up the _last_ call to `project()`.

At any rate, you should be using `EndBullet` directly instead of trying to use the CMake variable. The name shouldn’t change often, so using the variable loses some of its benefit. It also avoids this sort of confusion on how these CMake variables behave.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [January 11, 2024, 1:41pm UTC](https://discourse.cmake.org/t/im-having-trouble-linking-glfw-and-glm/9793/6 "2024-01-11T13:41:24Z")

</div>

If you’re doing this, you may as well just require CMake 3.13 since it won’t work in older versions anyways. Update this at the top of your project:

```cmake
cmake_minimum_required(VERSION 3.13)

```

And then you won’t need to set the policy either.
