# \`add\_compile\_options\` isn't adding options that start with \`-l\`

**URL:** <https://discourse.cmake.org/t/add-compile-options-isnt-adding-options-that-start-with-l/7925>\
**Category:** Code\
**Tags:** gen:makefiles\
**Created:** [April 18, 2023, 6:57am UTC](https://discourse.cmake.org/t/add-compile-options-isnt-adding-options-that-start-with-l/7925 "2023-04-18T06:57:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jack](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jack/32/2926_2.png) [@Jack](https://discourse.cmake.org/u/Jack)\
**Post date:** [April 18, 2023, 6:57am UTC](https://discourse.cmake.org/t/add-compile-options-isnt-adding-options-that-start-with-l/7925/1 "2023-04-18T06:57:21Z")

</div>

Hi all,

I’m attempting to modify a CMake file that is used to build for many platforms. The platform that I am specifically targeting to change is GHS (Green Hills Software). So I modified this:

```auto
        add_compile_options(
            -fno-omit-frame-pointer
        )

```

to this:

```auto
        if (GHSMULTI)
            add_compile_options(
              -lmulti # Be able to call functions from within MULTI
              -gtws # Generate Target Walkable Stack
              -ga # Force frame pointer
            )
        endif (GHSMULTI)

```

because the GHS compiler doesn’t understand `-fno-omit-frame-pointer`. It kinda worked in that `-fno-omit-frame-pointer` disappeared and was replaced by `-gtws` and `-ga`. However, `-lmulti` didn’t show up. This was verified by used Process Explorer and randomly selecting a build process and looking at the command line’s argument list.

I further tried to add to the `add_compile_options` the following switches: `-lnk=-wrap=malloc -lnk=-wrap=realloc -lnk=-wrap=calloc -lnk=-wrap=free`. but none showed up anywhere.

What am I missing?

---

<div class="post-metadata">

**Author:** ![Jack](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jack/32/2926_2.png) [@Jack](https://discourse.cmake.org/u/Jack)\
**Post date:** [April 18, 2023, 12:08pm UTC](https://discourse.cmake.org/t/add-compile-options-isnt-adding-options-that-start-with-l/7925/2 "2023-04-18T12:08:05Z")

</div>

Just on the off chance that it had something to do with the switch starting with `-l`, I just added the letter `a` in front of the `l` and it did show up as an error:

```auto
Warning: Found unknown option -alnk=-wrap=calloc in file.cpp

```

So, the question is, is CMake doing something to “help” me and if so, how to I tell it to stop being so “helpful”?

Oh, btw, the version I’m using is `cmake version 3.21.1`, but the first line in our files show `cmake_minimum_required(VERSION 3.1...3.10)`.

# EDIT:

Attempted to use

```auto
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-wrap=malloc,-wrap=realloc,-wrap=calloc,-wrap=free")

```

But that didn’t work either.

---

<div class="post-metadata">

**Author:** ![assignUser](https://discourse.cmake.org/user_avatar/discourse.cmake.org/assignuser/32/3367_2.png) [@assignUser](https://discourse.cmake.org/u/assignUser)\
**Post date:** [April 20, 2023, 11:13pm UTC](https://discourse.cmake.org/t/add-compile-options-isnt-adding-options-that-start-with-l/7925/3 "2023-04-20T23:13:04Z")

</div>

Hey Jack,  
I have no experience with GHS but my guess is that `-l<lib>` flags are filtered out by `add_compile_options` as they are supposed to be added with [link\_libraries](https://cmake.org/cmake/help/latest/command/link_libraries.html) so you could give `link_libraries(multi)` a try.

---

<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:** [April 24, 2023, 5:28am UTC](https://discourse.cmake.org/t/add-compile-options-isnt-adding-options-that-start-with-l/7925/4 "2023-04-24T05:28:21Z")

</div>

Yeah, this is probably it. We probably need a `COMPILER:` prefix to say that a flag is for the compiler (even if it looks like a link flag)

- `-lmulti`
- `-Wlove-me-do` (or some other `l`-starting warning name)

---

<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:** [April 24, 2023, 5:28am UTC](https://discourse.cmake.org/t/add-compile-options-isnt-adding-options-that-start-with-l/7925/5 "2023-04-24T05:28:52Z")

</div>

This is worth [an issue](https://gitlab.kitware.com/cmake/cmake/-/issues) by the way.

---

<div class="post-metadata">

**Author:** ![assignUser](https://discourse.cmake.org/user_avatar/discourse.cmake.org/assignuser/32/3367_2.png) [@assignUser](https://discourse.cmake.org/u/assignUser)\
**Post date:** [April 25, 2023, 12:39am UTC](https://discourse.cmake.org/t/add-compile-options-isnt-adding-options-that-start-with-l/7925/6 "2023-04-25T00:39:50Z")

</div>

This seems to be a GHS specific problem as I can add these flags fine with make files. As I don’t have GHS I can’t create/test a reprex for the issue ☹ Maybe @Jack can open one?

---

<div class="post-metadata">

**Author:** ![fdk17](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/f/ea666f/32.png) [@fdk17](https://discourse.cmake.org/u/fdk17)\
**Post date:** [April 29, 2023, 12:14am UTC](https://discourse.cmake.org/t/add-compile-options-isnt-adding-options-that-start-with-l/7925/7 "2023-04-29T00:14:12Z")

</div>

I checked in the CMake v3.23.0 and in the nightly build and cannot reproduce the issue with the `add_compile_options` command.

I tried:  
add\_compile\_options(-lmulti -Wl,-wrap=malloc,-wrap=realloc,-wrap=calloc,-wrap=free)  
add\_compile\_options(-lmulti -lnk=wrap=malloc -lnk=wrap=realloc -lnk=wrap=calloc -lnk=wrap=free)

The project files produced include the `-lmulti`, `-Wl` and the `-lnk` option. Running `gbuild` with the `-commands` shows the options being used during the build process.

FYI for others, `-lmulti` is used to link an executable against the `libmulti.a` library. Typically what I’ve seen, instead of using `-lmulti`, is to compile an executable with `-G` which should automatically add `libmulti.a` during the link phase.

> [@Jack](#):
>
> `Warning: Found unknown option -alnk=-wrap=calloc in file.cpp`

This is the output from `gbuild` when it does not recognize a driver option during the build process. I’m not aware of any way to turn off these warnings.
