# cmake picks up LDFLAGS from environment

**URL:** https://discourse.cmake.org/t/cmake-picks-up-ldflags-from-environment/4130
**Category:** Code
**Created:** [September 21, 2021, 3:24pm UTC](https://discourse.cmake.org/t/cmake-picks-up-ldflags-from-environment/4130 "2021-09-21T15:24:22Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![cmak](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@cmak](https://discourse.cmake.org/u/cmak)
#### Post date: [September 21, 2021, 6:35pm UTC](https://discourse.cmake.org/t/cmake-picks-up-ldflags-from-environment/4130/3 "2021-09-21T18:35:47Z")

</div>

> [@ben.boeckel](#):
>
> `CMAKE_EXE_LINKER_FLAGS_INIT`

```auto
$ cat CMakeLists.txt
project(helloworld)
add_executable(helloworld helloworld.cpp)
set(CMAKE_EXE_LINKER_FLAGS_INIT )

$ env | grep LDFLAGS
LDFLAGS=-Wl,--as-needed

```

If I build this I can see cmake passing LDFLAGS to the linker

```bash
[50%] Building CXX object CMakeFiles/helloworld.dir/helloworld.cpp.o
/usr/bin/c++ -o CMakeFiles/helloworld.dir/helloworld.cpp.o -c /usr/local/src/cmake_example/helloworld.cpp
[100%] Linking CXX executable helloworld
/usr/bin/cmake -E cmake_link_script CMakeFiles/helloworld.dir/link.txt --verbose=1
/usr/bin/c++ -Wl,--as-needed -rdynamic CMakeFiles/helloworld.dir/helloworld.cpp.o -o helloworld
make[2]: Leaving directory '/usr/local/src/cmake_example/build'
[100%] Built target helloworld
make[1]: Leaving directory '/usr/local/src/cmake_example/build'
/usr/bin/cmake -E cmake_progress_start /usr/local/src/cmake_example/build/CMakeFiles 0

```

---

_[View the full topic](https://discourse.cmake.org/t/cmake-picks-up-ldflags-from-environment/4130)._
