# New user - Can't get file(ARCHIVE\_EXTRACT ...) to work

**URL:** https://discourse.cmake.org/t/new-user-cant-get-file-archive-extract-to-work/10135
**Category:** Code
**Created:** [February 19, 2024, 10:08am UTC](https://discourse.cmake.org/t/new-user-cant-get-file-archive-extract-to-work/10135 "2024-02-19T10:08:16Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![tuscan](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/d26b3c/32.png) [@tuscan](https://discourse.cmake.org/u/tuscan)
#### Post date: [February 19, 2024, 10:08am UTC](https://discourse.cmake.org/t/new-user-cant-get-file-archive-extract-to-work/10135/1 "2024-02-19T10:08:16Z")

</div>

Hi

I am a new user of CMake (literally day one) and everything has gone swimmingly so far except for one thing - I am getting an error when use file(ARCHIVE\_EXTRACT). I am guessing it is something pretty obvious, but if someone could point me in the right direction I would be most grateful.

I can demo the problem very simply with the following CMakeLists.txt: (Note I have really stripped this down to the bare minimum!)

cmake\_minimum\_required(VERSION 3.25)

project(arctest VERSION 1.0 DESCRIPTION “Archive Extract test” LANGUAGES C CXX)

file(ARCHIVE\_EXTRACT INPUT “test.tar.gz”)

The “test.tar.gz” file is a simple archive with a couple of text files in it, created using “tar -czvf …”

When I run “cmake -B build” I get the following error:

CMake Error: Problem with archive\_read\_open\_file(): Failed to open ‘test.tar.gz’

CMake Error at CMakeLists.txt:3 (file):

file failed to extract: test.tar.gz

However, if I change line 3 of the CMakeLists file to

file(ARCHIVE\_EXTRACT INPUT “test.tar.gz” LIST\_ONLY)

it completes fine - listing the files in the archive.

BTW the system I am running on is fully updated Ubuntu and CMake 3.28.3

Best regards

---

<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: [February 27, 2024, 12:53pm UTC](https://discourse.cmake.org/t/new-user-cant-get-file-archive-extract-to-work/10135/2 "2024-02-27T12:53:40Z")

</div>

`LIST_ONLY` doesn’t change the working directory while extraction does (to the `DESTINATION`). This causes the relative path to work for `LIST_ONLY` but fail for the extraction case. Use an absolute path to the `INPUT` file. I’ve filed an MR to update documentation here:

[https://gitlab.kitware.com/cmake/cmake/-/merge\_requests/9291](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9291)

---

<div class="post-metadata">

### Author: ![tuscan](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/d26b3c/32.png) [@tuscan](https://discourse.cmake.org/u/tuscan)
#### Post date: [February 27, 2024, 1:37pm UTC](https://discourse.cmake.org/t/new-user-cant-get-file-archive-extract-to-work/10135/3 "2024-02-27T13:37:41Z")

</div>

Many thanks for the explanation - I knew it must be a simple ‘newbie’ thing!
