# how to custom the static library ar process

**URL:** https://discourse.cmake.org/t/how-to-custom-the-static-library-ar-process/4437
**Category:** Code
**Created:** [November 6, 2021, 11:52am UTC](https://discourse.cmake.org/t/how-to-custom-the-static-library-ar-process/4437 "2021-11-06T11:52:31Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Princekin](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/a8b319/32.png) [@Princekin](https://discourse.cmake.org/u/Princekin)
#### Post date: [November 6, 2021, 11:52am UTC](https://discourse.cmake.org/t/how-to-custom-the-static-library-ar-process/4437/1 "2021-11-06T11:52:32Z")

</div>

I want to build a static library name `xcrt` that use CMake,

```auto
SET(CMAKE_AR "i386-elf-ar")
set(CMAKE_STATIC_LINKER_FLAGS rc CACHE STRING "" FORCE)
add_library(xcrt STATIC
	xcrt_SRC}
)

```

when build, it executes the command:

```auto
i386-elf-ar cr libxcrt.a rc CMakeFiles/xcrt.dir/x86/crt1.asm.o CMakeFiles/xcrt.dir/x86/crti.asm.o CMakeFiles/xcrt.dir/x86/crtn.asm.o

```

I don’t want the `cr` option to follow after the `i386-elf-ar` command, I just want to use `rc` option to replace `cr` option, I had tried to set follow statement in CMakeList.txt.

```auto
set(CMAKE_C_CREATE_STATIC_LIBRARY "<CMAKE_AR> rc <TARGET> <LINK_FLAGS> <OBJECTS> ")
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> rc <TARGET> <LINK_FLAGS> <OBJECTS>")

```

but it does not work at all, what I should do when I need to use `rc` option to replace `cr` option? thanks a lot!

---

<div class="post-metadata">

### Author: ![Princekin](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/a8b319/32.png) [@Princekin](https://discourse.cmake.org/u/Princekin)
#### Post date: [November 6, 2021, 2:18pm UTC](https://discourse.cmake.org/t/how-to-custom-the-static-library-ar-process/4437/2 "2021-11-06T14:18:43Z")

</div>

here is files and subdirectory in the `xcrt` directory:

```auto
├── CMakeLists.txt
├── Makefile
└── x86
    ├── CMakeLists.txt
    ├── Makefile
    ├── crt1.asm
    ├── crti.asm
    └── crtn.asm

```

I had tried to add following statement in CMakeList.txt.

```auto
set(CMAKE_C_ARCHIVE_CREATE " Scr ")
set(CMAKE_CXX_ARCHIVE_CREATE " Scr ")
set(CMAKE_C_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ")
set(CMAKE_CXX_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ")
set(CMAKE_ASM_ARCHIVE_CREATE " Scr ")
set(CMAKE_ASM_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ")
set(CMAKE_ASM_NASM_ARCHIVE_CREATE " Scr ")
set(CMAKE_ASM_NASM_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ")

```

but It still does not change anything about the ar process, when execute `make` command, it still executes the command:

```auto
i386-elf-ar cr libxcrt.a rc CMakeFiles/xcrt.dir/x86/crt1.asm.o CMakeFiles/xcrt.dir/x86/crti.asm.o CMakeFiles/xcrt.dir/x86/crtn.asm.o

```

I don’t know why, could anyone helps me, thanks a lot!

---

<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: [November 6, 2021, 8:13pm UTC](https://discourse.cmake.org/t/how-to-custom-the-static-library-ar-process/4437/3 "2021-11-06T20:13:52Z")

</div>

> [@Princekin](#):
>
> ```auto
> SET(CMAKE_AR "i386-elf-ar")
> set(CMAKE_STATIC_LINKER_FLAGS rc CACHE STRING "" FORCE)
> 
> ```

You want to look into CMAKE\_TOOLCHAIN\_FILES. What you are currently doing isn’t correct at all.

---

<div class="post-metadata">

### Author: ![Princekin](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/a8b319/32.png) [@Princekin](https://discourse.cmake.org/u/Princekin)
#### Post date: [November 7, 2021, 12:59am UTC](https://discourse.cmake.org/t/how-to-custom-the-static-library-ar-process/4437/4 "2021-11-07T00:59:44Z")

</div>

after multiple tries, I found the reason, because my source files are all .asm files, I must use CMAKE\_ASM\_NASM\_CREATE\_STATIC\_LIBRARY, not CMAKE\_C\_CREATE\_STATIC\_LIBRARY, you can find `CMAKE_DEPENDS_LANGUAGES` from the file which in `/CMakeFiles/*.dir/DependInfo.cmake`,the worked ar process is:

```auto
set(CMAKE_AR "i386-elf-ar")
set(CMAKE_ASM_NASM_CREATE_STATIC_LIBRARY "<CMAKE_AR> rc <TARGET> <OBJECTS> ")

```

hope it can help someone!
