# CMake 3.21 rc-1 | Threads::Threads not found

**URL:** https://discourse.cmake.org/t/cmake-3-21-rc-1-threads-threads-not-found/3630
**Category:** Development
**Tags:** os:windows, comp:msvc
**Created:** [June 25, 2021, 9:34pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-threads-threads-not-found/3630 "2021-06-25T21:34:18Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [June 25, 2021, 9:34pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-threads-threads-not-found/3630/1 "2021-06-25T21:34:18Z")

</div>

Since switching to CMake 3.21 we are getting a host of errors relating to “Threads::Threads”

This is happening on Windows/MSVC.

I get multiple error message like this after configuration is done

```auto
-- Configuring done
CMake Error at CMakeLists.txt:33 (add_library):
  Target "foobar" links to target "Threads::Threads" but the target was not
  found. Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?

```

And when I check the VS solution I found this in it.

![image](https://discourse.cmake.org/uploads/default/original/2X/6/655db1b84a464876f6f69ac82c79968356aa0753.png)

It’s trying to link a library called “Threads::Threads.lib”

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [June 29, 2021, 6:43pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-threads-threads-not-found/3630/2 "2021-06-29T18:43:26Z")

</div>

I’ve managed to create a [SSCCE](http://sscce.org/) to reproduce the issue.

I’m on Windows, and my generator is VS2019. This worked just fine in 3.20 but not 3.21.

[threads\_threads.zip](https://discourse.cmake.org/uploads/short-url/hZktsSl6yAuCdErtDpYwXLR3qPV.zip) (1.9 KB)

Here is the layout of the project:  
 ![image](https://discourse.cmake.org/uploads/default/original/2X/5/5f7674fa97571845f22a23035ec0856240a83e95.png)

CMakeLists.txt

```auto
cmake_minimum_required(VERSION 3.21)
project(FOOBAR LANGUAGES "CXX")
add_executable(baz main.cpp)
add_subdirectory(temp)
target_link_libraries(baz PRIVATE foo)

```

temp/CMakeLists.txt

```auto
add_library(foo STATIC)
add_subdirectory(src)

```

temp\src\CMakeLists.txt

```auto
find_package(Threads REQUIRED)
target_link_libraries(foo PRIVATE Threads::Threads)
target_sources(foo PRIVATE foo.cpp)
target_include_directories(foo PUBLIC .)

```

EDIT:

You will get this error message

```auto
CMake Error at CMakeLists.txt:5 (add_executable):
  Target "baz" links to target "Threads::Threads" but the target was not
  found. Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?

```

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [June 29, 2021, 6:55pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-threads-threads-not-found/3630/3 "2021-06-29T18:55:00Z")

</div>

Thanks. I can reproduce that on Linux too. I’ll take a look.

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [June 29, 2021, 6:59pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-threads-threads-not-found/3630/4 "2021-06-29T18:59:30Z")

</div>

Not sure if this helps but, if I change the project slightly it works now.

temp/CMakeLists.txt

```auto
add_library(foo STATIC)
add_subdirectory(src)

# Move these 2 calls out of the 'src' dir CMakeLists.txt
find_package(Threads REQUIRED)
target_link_libraries(foo PRIVATE Threads::Threads)

```

temp\src\CMakeLists.txt

```auto
target_sources(foo PRIVATE foo.cpp)
target_include_directories(foo PUBLIC .)

```

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [June 29, 2021, 7:00pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-threads-threads-not-found/3630/5 "2021-06-29T19:00:25Z")

</div>

Perhaps it’s a scoping issue that effects imported targets?

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [June 29, 2021, 7:23pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-threads-threads-not-found/3630/6 "2021-06-29T19:23:20Z")

</div>

I’ve opened [CMake Issue 22363](https://gitlab.kitware.com/cmake/cmake/-/issues/22363) to track this regression. I posted an even simpler minimal example there. Please follow the issue for further updates.

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [June 30, 2021, 11:21am UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-threads-threads-not-found/3630/7 "2021-06-30T11:21:49Z")

</div>

> [@buildSystemPerson](#):
>
> Since switching to CMake 3.21 we

@buildSystemPerson thanks for trying out the release candidate!
