# X11/Motif: find\_package() imported targets vs variables

**URL:** https://discourse.cmake.org/t/x11-motif-find-package-imported-targets-vs-variables/8611
**Category:** Usage
**Created:** [July 26, 2023, 10:31pm UTC](https://discourse.cmake.org/t/x11-motif-find-package-imported-targets-vs-variables/8611 "2023-07-26T22:31:46Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![tomoreilly](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/439d5e/32.png) [@tomoreilly](https://discourse.cmake.org/u/tomoreilly)
#### Post date: [July 26, 2023, 10:31pm UTC](https://discourse.cmake.org/t/x11-motif-find-package-imported-targets-vs-variables/8611/1 "2023-07-26T22:31:46Z")

</div>

I “inherited” a CMakeLists.txt that contains this:

```auto
find_package(X11 REQUIRED)
find_package(Motif REQUIRED)

add_executable(mbgrdviz mbgrdviz_callbacks.c mbgrdviz_creation.c
                        mbgrdviz_main.c)

# Specify X11/Motif imported targets to target_link_libraries
target_link_libraries(mbgrdviz PRIVATE mbaux mbview Motif::Motif X11::Xt)

```

The built executable runs fine on MacOS. But on ubuntu 20.04.2 it generates this error:

> % mbgrdviz  
> X Error of failed request: BadWindow (invalid Window parameter)  
> Major opcode of failed request: 19 (X\_DeleteProperty)  
> Resource id in failed request: 0x0  
> Serial number of failed request: 119  
> Current serial number in output stream: 123

But if I replace the imported targets in this:

`target_link_libraries(mbgrdviz PRIVATE mbaux mbview Motif::Motif X11::Xt)`

with variables returned by find\_package() (something I’m more familiar with):

```auto
target_link_libraries(mbgrdviz PRIVATE mbaux mbview
		${MOTIF_LIBRARIES} ${X11_LIBRARIES} ${X11_Xt_LIB})

```

the resulting executable runs fine on both MacOS and ubuntu.

What’s the difference between the “imported target” and “variables” approaches? I.e. instead of “Motif::Motif X11:Xt” I specify “${MOTIF\_LIBRARIES} ${X11\_LIBRARIES} and ${X11\_Xt\_LIB}” to target\_link\_libraries(). Why would the imported target approach work on MacOS but fail on ubuntu?

Thanks!

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [July 26, 2023, 11:25pm UTC](https://discourse.cmake.org/t/x11-motif-find-package-imported-targets-vs-variables/8611/2 "2023-07-26T23:25:55Z")

</div>

In general, always prefer to use imported targets over variables. The imported targets also provide things like header search paths, compiler defines, etc. which the variables don’t.

In this case, the list of libraries you link using variables appears to be different to the list of imported targets. Perhaps you are missing `X11::X11` in your list of imported targets?

You can see the list of libraries the variables would pull in by adding the following line to your project:

```cmake
message(STATUS
    "MOTIF_LIBRARIES = ${MOTIF_LIBRARIES}\n"
    "X11_LIBRARIES = ${X11_LIBRARIES}\n"
    "X11_Xt_LIB = ${X11_Xt_LIB}"
)

```

As to why this results in different behavior at runtime, it may relate to libraries that are dynamically loaded at runtime rather than linked, but that’s just a guess. Let’s see what the above output reveals.

---

<div class="post-metadata">

### Author: ![tomoreilly](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/439d5e/32.png) [@tomoreilly](https://discourse.cmake.org/u/tomoreilly)
#### Post date: [July 27, 2023, 2:27am UTC](https://discourse.cmake.org/t/x11-motif-find-package-imported-targets-vs-variables/8611/3 "2023-07-27T02:27:07Z")

</div>

Thanks! How can I see the list of libraries and headers that will be pulled in from imported targets?

---

<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: [July 27, 2023, 2:49am UTC](https://discourse.cmake.org/t/x11-motif-find-package-imported-targets-vs-variables/8611/4 "2023-07-27T02:49:15Z")

</div>

That’s not generally available as the transitive closure needs to be queried manually. But you can ask the targets for their `INTERFACE_INCLUDE_DIRECTORIES` and `INTERFACE_LINK_LIBRARIES` properties to take a peek.

---

<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: [July 27, 2023, 2:59am UTC](https://discourse.cmake.org/t/x11-motif-find-package-imported-targets-vs-variables/8611/5 "2023-07-27T02:59:08Z")

</div>

By the way, once you figure out what is missing, it might be worth filing an issue so that `FindX11` can encode this in these properties for macOS/Quartz usage.

---

<div class="post-metadata">

### Author: ![tomoreilly](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/439d5e/32.png) [@tomoreilly](https://discourse.cmake.org/u/tomoreilly)
#### Post date: [July 27, 2023, 5:00pm UTC](https://discourse.cmake.org/t/x11-motif-find-package-imported-targets-vs-variables/8611/6 "2023-07-27T17:00:23Z")

</div>

Thanks @ben.boeckel - pardon my newbie-ness but how exactly would I modify my CMakeLists.txt to peek into `INTERFACE_INCLUDE_DIRECTORIES` and `INTERFACE_LINK_LIBRARIES` to see what’s provided by the X11 and Motif packages? I.e. I currently have:

```auto
find_package(X11 REQUIRED)
find_package(Motif REQUIRED)

add_executable(mbgrdviz mbgrdviz_callbacks.c mbgrdviz_creation.c
                        mbgrdviz_main.c)

# Specify X11/Motif imported targets to target_link_libraries
target_link_libraries(mbgrdviz PRIVATE mbaux mbview Motif::Motif X11::Xt)

```

How would I modify this?

---

<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: [July 29, 2023, 8:43pm UTC](https://discourse.cmake.org/t/x11-motif-find-package-imported-targets-vs-variables/8611/7 "2023-07-29T20:43:30Z")

</div>

`get_property(output TARGET X11::Xt PROPERTY propname)`
