# LINK\_FLAGS order in CMake link step

**URL:** https://discourse.cmake.org/t/link-flags-order-in-cmake-link-step/2803
**Category:** Usage
**Created:** [February 19, 2021, 7:34pm UTC](https://discourse.cmake.org/t/link-flags-order-in-cmake-link-step/2803 "2021-02-19T19:34:56Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![alainlou](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alainlou/32/1222_2.png) [@alainlou](https://discourse.cmake.org/u/alainlou)
#### Post date: [February 19, 2021, 7:34pm UTC](https://discourse.cmake.org/t/link-flags-order-in-cmake-link-step/2803/1 "2021-02-19T19:34:56Z")

</div>

OS: Ubuntu 18.04

Version: 3.10.2

Other relevant info:

```auto
set(CMAKE_CXX_COMPILER dpcpp)
cmake_minimum_required (VERSION 3.4)

```

I have the following target

```auto
add_executable(${EMULATOR_TARGET} ${SOURCE_FILE} ${HEADER_FILE})
add_custom_target(fpga_emu DEPENDS ${EMULATOR_TARGET})
add_dependencies(${EMULATOR_TARGET} create_library_archive)
set_target_properties(${EMULATOR_TARGET} PROPERTIES COMPILE_FLAGS "-fintelfpga -DFPGA_EMULATOR")
set_target_properties(${EMULATOR_TARGET} PROPERTIES LINK_FLAGS "-fintelfpga ${LIBRARY_ARCHIVE}")

```

CMake’s generated link command: `dpcpp -fintelfpga lib.a CMakeFiles/use_library.fpga_emu.dir/use_library.cpp.o -o ../use_library.fpga_emu`

I was told this is the wrong order on Linux, since the GNU linker is only “forward looking”. Is there a way to get the link flags to appear after the object file, something like this?

`dpcpp CMakeFiles/use_library.fpga_emu.dir/use_library.cpp.o -fintelfpga lib.a -o ../use_library.fpga_emu`

Thanks team!

---

<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 19, 2021, 8:22pm UTC](https://discourse.cmake.org/t/link-flags-order-in-cmake-link-step/2803/2 "2021-02-19T20:22:10Z")

</div>

I don’t think CMake offers such fine-grained control over the link line.

Cc: @brad.king

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [February 22, 2021, 2:11pm UTC](https://discourse.cmake.org/t/link-flags-order-in-cmake-link-step/2803/3 "2021-02-22T14:11:26Z")

</div>

`target_link_libraries` supports passing flags in addition to libraries. Although `target_link_options` should be preferred for most flags, `target_link_libraries` is appropriate for flags meant to add toolchain-provided libraries.

---

<div class="post-metadata">

### Author: ![alainlou](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alainlou/32/1222_2.png) [@alainlou](https://discourse.cmake.org/u/alainlou)
#### Post date: [February 22, 2021, 6:12pm UTC](https://discourse.cmake.org/t/link-flags-order-in-cmake-link-step/2803/4 "2021-02-22T18:12:47Z")

</div>

Awesome, that worked, thanks Brad!
