# window env variable and cmake path

**URL:** https://discourse.cmake.org/t/window-env-variable-and-cmake-path/5410
**Category:** Usage
**Tags:** os:windows
**Created:** [April 8, 2022, 2:55am UTC](https://discourse.cmake.org/t/window-env-variable-and-cmake-path/5410 "2022-04-08T02:55:31Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![alice](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alice/32/1615_2.png) [@alice](https://discourse.cmake.org/u/alice)
#### Post date: [April 8, 2022, 2:55am UTC](https://discourse.cmake.org/t/window-env-variable-and-cmake-path/5410/1 "2022-04-08T02:55:31Z")

</div>

I set the windows env variable  
path=D:\test\fmt\debug

Then I let the cmakelist

```auto
	find_library(_FMT_LIB 
		NAMES fmt
		PATHS "D:\test\fmt\release"

```

The final result will be the D:\test\fmt\debug  
How to let it to D:\test\fmt\release

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [April 8, 2022, 8:29pm UTC](https://discourse.cmake.org/t/window-env-variable-and-cmake-path/5410/2 "2022-04-08T20:29:54Z")

</div>

I suspect your problem is due to the use of backslashes in the string you give to the `PATHS` argument. The `\t` will be seen as a tab character and `\r` as a carriage return. Paths should normally be written with forward slashes in CMake code, even for Windows. Alternatively, if you want a backslash, you need to escape it, so your string would have to be either `"D:/test/fmt/release"` or `"D:\\test\\fmt\\release"`.

---

<div class="post-metadata">

### Author: ![alice](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alice/32/1615_2.png) [@alice](https://discourse.cmake.org/u/alice)
#### Post date: [April 11, 2022, 12:59am UTC](https://discourse.cmake.org/t/window-env-variable-and-cmake-path/5410/3 "2022-04-11T00:59:40Z")

</div>

I use three times PATHS  
Can I only declare a variable to replace them?  
I dont know what is the function?

```auto
	find_library(_opencv_LIB
		NAMES opencv.lib
		PATHS "${LIB_ROOT}/opencv/include"
	)
	find_library(_opencv_LIB
		NAMES opencv_wrapper.lib
		PATHS "${LIB_ROOT}/opencv/include"
	)
	find_path(_opencv_INCLUDE_DIRS
		NAMES include/opencv_app.h
		PATHS "${LIB_ROOT}/opencv"
	)

```

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [April 11, 2022, 1:22am UTC](https://discourse.cmake.org/t/window-env-variable-and-cmake-path/5410/4 "2022-04-11T01:22:58Z")

</div>

> [@alice](#):
>
> ```auto
> find_path(_opencv_INCLUDE_DIRS
> NAMES include/opencv_app.h
> PATHS "${LIB_ROOT}/opencv"
> )
> 
> ```

Arguments following `NAMES` cannot include a directory, they must be file names only.

> [@alice](#):
>
> I use three times PATHS  
> Can I only declare a variable to replace them?  
> I dont know what is the function?

I can’t follow what you’re asking. Can you please provide more detail so that your question(s) are clearer?

---

<div class="post-metadata">

### Author: ![alice](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alice/32/1615_2.png) [@alice](https://discourse.cmake.org/u/alice)
#### Post date: [April 11, 2022, 1:36am UTC](https://discourse.cmake.org/t/window-env-variable-and-cmake-path/5410/5 "2022-04-11T01:36:25Z")

</div>

like this  
pseudocode

```auto
set(OPENCVpath "${LIB_ROOT}/opencv")
	find_library(_opencv_LIB
		NAMES opencv.lib
	)
	find_library(_opencv_LIB
		NAMES opencv_wrapper.lib
	)
	find_path(_opencv_INCLUDE_DIRS
		NAMES opencv_app.h
	)

```
