# Why is cflags appended to link flags?

**URL:** https://discourse.cmake.org/t/why-is-cflags-appended-to-link-flags/7356
**Category:** Usage
**Created:** [January 29, 2023, 8:46am UTC](https://discourse.cmake.org/t/why-is-cflags-appended-to-link-flags/7356 "2023-01-29T08:46:51Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![wdyichen](https://discourse.cmake.org/user_avatar/discourse.cmake.org/wdyichen/32/3126_2.png) [@wdyichen](https://discourse.cmake.org/u/wdyichen)
#### Post date: [January 29, 2023, 8:46am UTC](https://discourse.cmake.org/t/why-is-cflags-appended-to-link-flags/7356/1 "2023-01-29T08:46:51Z")

</div>

I set set(CMAKE\_SYSTEM\_NAME Generic), then set CMAKE\_C\_FLAGS and CMAKE\_EXE\_LINKER\_FLAGS,  
I found that in addition to using the CMAKE\_EXE\_LINKER\_FLAGS I set, the parameter CMAKE\_C\_FLAGS was also appended automatically when linking.  
Is there any way to remove the CMAKE\_C\_FLAGS parameter from the link flags?

---

<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 29, 2023, 1:15pm UTC](https://discourse.cmake.org/t/why-is-cflags-appended-to-link-flags/7356/2 "2023-01-29T13:15:02Z")

</div>

No. Some “compiler” flags have effects on the linker too (e.g., `-pthread` or `-fsanitize=`), so they are passed to both rules.

Why do you want to remove the flags?

---

<div class="post-metadata">

### Author: ![wdyichen](https://discourse.cmake.org/user_avatar/discourse.cmake.org/wdyichen/32/3126_2.png) [@wdyichen](https://discourse.cmake.org/u/wdyichen)
#### Post date: [January 30, 2023, 1:50am UTC](https://discourse.cmake.org/t/why-is-cflags-appended-to-link-flags/7356/3 "2023-01-30T01:50:24Z")

</div>

I don’t think you’re getting it right. Things like -pthread only work at link time, it doesn’t work at compile time.

---

<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 30, 2023, 3:27am UTC](https://discourse.cmake.org/t/why-is-cflags-appended-to-link-flags/7356/4 "2023-01-30T03:27:30Z")

</div>

You’re thinking of `-lpthread`. `-pthread` [also affects the compilation](https://stackoverflow.com/questions/23250863/difference-between-pthread-and-lpthread-while-compiling). Namely, it sets the `_REENTRANT` and `__USE_REENTRANT` symbols (which probably affect the standard libraries in various ways).
