# Remove linker flag needed by library, but not by test programs

**URL:** https://discourse.cmake.org/t/remove-linker-flag-needed-by-library-but-not-by-test-programs/1860
**Category:** Code
**Created:** [September 19, 2020, 9:51am UTC](https://discourse.cmake.org/t/remove-linker-flag-needed-by-library-but-not-by-test-programs/1860 "2020-09-19T09:51:18Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![starfire](https://discourse.cmake.org/user_avatar/discourse.cmake.org/starfire/32/835_2.png) [@starfire](https://discourse.cmake.org/u/starfire)
#### Post date: [September 19, 2020, 9:51am UTC](https://discourse.cmake.org/t/remove-linker-flag-needed-by-library-but-not-by-test-programs/1860/1 "2020-09-19T09:51:18Z")

</div>

I am migrating a project from autotools to CMake. One part is a static library with version information and a few testprograms in a subdirectory. So I tried:

```
add_library(wraster STATIC ${SOURCES})
target_link_libraries(wraster PRIVATE -version-info=${WRASTER_VERSION})
add_subdirectory(tests)

```

and in the subdirectory:

```
add_executable(testdraw testdraw.c)
target_link_libraries(testdraw PRIVATE wraster)

```

The library gets built, but unfortunately CMake adds the linker flags from the library also to the testprograms which causes an error, because of the version information:

`cc: error: unrecognized command-line option ‘-version-info=6:0:0’`

(The compiler flags are set for the programs as well)  
How can I avoid this without removing the version info?

TIA and best regards - Andreas

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [September 19, 2020, 10:36am UTC](https://discourse.cmake.org/t/remove-linker-flag-needed-by-library-but-not-by-test-programs/1860/2 "2020-09-19T10:36:43Z")

</div>

- First, to set link options, use `target_link_options` rather than `target_link_libraries`.
- Second, `target_link_options` is not usable with static libraries.

In your case, you have to use [STATIC\_LIBRARY\_OPTIONS](https://cmake.org/cmake/help/latest/prop_tgt/STATIC_LIBRARY_OPTIONS.html#prop_tgt:STATIC_LIBRARY_OPTIONS) target property:

```cmake
add_library(wraster STATIC ${SOURCES})
set_property (TARGET wraster PROPERTY STATIC_LIBRARY_OPTIONS "-version-info=${WRASTER_VERSION}")

```
