# VS generator add switch before /link switch

**URL:** https://discourse.cmake.org/t/vs-generator-add-switch-before-link-switch/2425
**Category:** Usage
**Tags:** gen:vs
**Created:** [December 24, 2020, 5:48am UTC](https://discourse.cmake.org/t/vs-generator-add-switch-before-link-switch/2425 "2020-12-24T05:48:49Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![amontse](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@amontse](https://discourse.cmake.org/u/amontse)
#### Post date: [December 24, 2020, 5:48am UTC](https://discourse.cmake.org/t/vs-generator-add-switch-before-link-switch/2425/1 "2020-12-24T05:48:49Z")

</div>

Hello,

The following mimic command to be run during the Link stage is generated by CMake with VS generator:

`cl.exe /Fe"out.exe" main.obj /Zi /WX- /MDd /nologo /link /machine:x64 kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib`

The arguments passed after the switch /link are expected to be passed to the linker.

Using target\_link\_options, the option will be added after the /link switch.

I would like to pass additional argument BEFORE the /link switch. Is there a way to do it in CMakeLists.txt?

Best Regards,  
Amon

---

<div class="post-metadata">

### Author: ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)
#### Post date: [December 24, 2020, 9:24am UTC](https://discourse.cmake.org/t/vs-generator-add-switch-before-link-switch/2425/2 "2020-12-24T09:24:19Z")

</div>

> [@amontse](#):
>
> The arguments passed after the switch /link are expected to be passed to the linker.

AFAIK, all arguments are passed to the linker. For instance, the linker needs `/Fe"out.exe"` to know the filename of the output, and `main.obj` to know what to include, and both these arguments are passed before `/link`.

If you want to change how `main.cpp` (or `main.cc`, or `main.c`) is compiled, then you should use `target_compile_options`.

I hope this helps.
