# IMPORTED\_LINK\_INTERFACE\_LANGUAGES property is ignored?

**URL:** <https://discourse.cmake.org/t/imported-link-interface-languages-property-is-ignored/4909>\
**Category:** Code\
**Created:** [January 26, 2022, 5:25pm UTC](https://discourse.cmake.org/t/imported-link-interface-languages-property-is-ignored/4909 "2022-01-26T17:25:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![pcercuei](https://discourse.cmake.org/user_avatar/discourse.cmake.org/pcercuei/32/2133_2.png) [@pcercuei](https://discourse.cmake.org/u/pcercuei)\
**Post date:** [January 26, 2022, 5:25pm UTC](https://discourse.cmake.org/t/imported-link-interface-languages-property-is-ignored/4909/1 "2022-01-26T17:25:15Z")

</div>

Hi,

A possible bug related to the IMPORTED\_LINK\_INTERFACE\_LANGUAGES  
property.

I created a very simple CMake script to show my issue, available here:

> <https://gist.github.com/pcercuei/44462d30de7eac0f195118d7ec545c91>

The test.c file referenced in the script is a dead simple example  
source file, whose goal is only to call enough libxml2 functions for it  
to be linked. I uploaded it there:

> <https://gist.github.com/pcercuei/ffa55a45a44036957670100cedf2b4d3>

The libxml2 library is itself written in C, but has an optional  
dependency on libicu, which is a C++ library with a C interface. In my  
test case, the libxml2-config.cmake file provided by libxml2 is used,  
and the libxml2 and dependencies have been statically compiled.

My problem is that the test.c will fail to link, as the compiler  
complains about missing C++ symbols. Indeed, it is linked with gcc and  
not g++, and the stdc++ library is not passed on the command line.

Note that my script sets the IMPORTED\_LINK\_INTERFACE\_LANGUAGES property  
to CXX on the LibXml2::LibXml2 library to try to force things, but this  
property is already set on the libicu targets, that are linked as part  
of the static build.

My expectation is that having IMPORTED\_LINK\_INTERFACE\_LANGUAGES set to  
CXX on an imported target would switch the compiler from gcc to g++,  
but this does not seem to be the case.

Note that I also tried:  
project(test LANGUAGES C CXX)

But this actually doesn’t change anything, and gcc will still be used  
for linking. Besides, my project is C, my dependencies are C, so I  
don’t want to add a dependency on C++ just to address a particular case.

Any ideas?

Cheers,  
-Paul

---

<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:** [January 27, 2022, 2:06pm UTC](https://discourse.cmake.org/t/imported-link-interface-languages-property-is-ignored/4909/2 "2022-01-27T14:06:20Z")

</div>

Please trace through the `libxml2-config.cmake` code that calls `add_library(LibXml2::LibXml2 ...)`. What kind of library target does it create?

[`IMPORTED_LINK_INTERFACE_LANGUAGES`](https://cmake.org/cmake/help/v3.22/prop_tgt/IMPORTED_LINK_INTERFACE_LANGUAGES.html) is meaningful only for `STATIC` `IMPORTED` library targets.

---

<div class="post-metadata">

**Author:** ![pcercuei](https://discourse.cmake.org/user_avatar/discourse.cmake.org/pcercuei/32/2133_2.png) [@pcercuei](https://discourse.cmake.org/u/pcercuei)\
**Post date:** [January 27, 2022, 3:08pm UTC](https://discourse.cmake.org/t/imported-link-interface-languages-property-is-ignored/4909/3 "2022-01-27T15:08:47Z")

</div>

I uploaded the libxml2-config.cmake here:

> <https://gist.github.com/pcercuei/dcaf5b85cfc6076b153f381470bde558>

It does:  
add\_library(LibXml2::LibXml2 UNKNOWN IMPORTED)

Note that FindICU.cmake (which is shipped as part of CMake) does this  
too, and sets the IMPORTED\_LINK\_INTERFACE\_LANGUAGES property as well,  
and it fails there too.

The following example, which uses only scripts provided by CMake, shows  
the exact same problem:

```auto
cmake_minimum_required(VERSION 3.16)
project(test LANGUAGES C)

set(BUILD_SHARED_LIBS OFF)

include(CMakeFindDependencyMacro)
find_dependency(ICU COMPONENTS data i18n uc)

add_executable(test test.c)
target_link_libraries(test ${ICU_LIBRARIES})

```

```auto
#include <unicode/ucnv.h>

int main(void)
{
ucnv_close(NULL);

return 0;
}

```

---

<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:** [January 27, 2022, 8:41pm UTC](https://discourse.cmake.org/t/imported-link-interface-languages-property-is-ignored/4909/4 "2022-01-27T20:41:31Z")

</div>

> [@pcercuei](#):
>
> It does:  
> add\_library(LibXml2::LibXml2 UNKNOWN IMPORTED)

`UNKNOWN` is not `STATIC`, so `IMPORTED_LINK_INTERFACE_LANGUAGES` won’t be used.

Package configuration files come with the projects they describe, so that file should be able to specify the real type of the library: `SHARED` or `STATIC`.

---

<div class="post-metadata">

**Author:** ![pcercuei](https://discourse.cmake.org/user_avatar/discourse.cmake.org/pcercuei/32/2133_2.png) [@pcercuei](https://discourse.cmake.org/u/pcercuei)\
**Post date:** [January 27, 2022, 8:55pm UTC](https://discourse.cmake.org/t/imported-link-interface-languages-property-is-ignored/4909/5 "2022-01-27T20:55:37Z")

</div>

Hi Brad,

> Package configuration files come with the projects they describe

If you read my response carefully, I just gave you an example that does _not_ depend on any package configuration file outside of CMake.

Please have a look at:

> <https://github.com/Kitware/CMake/blob/master/Modules/FindICU.cmake#L359-L368>

You will see that it does create a UNKNOWN IMPORTED library, and sets the IMPORTED\_LINK\_INTERFACE\_LANGUAGES property to CXX. My expectation is that this should work.

---

<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:** [January 28, 2022, 2:24pm UTC](https://discourse.cmake.org/t/imported-link-interface-languages-property-is-ignored/4909/6 "2022-01-28T14:24:33Z")

</div>

See [CMake Issue 18564](https://gitlab.kitware.com/cmake/cmake/-/issues/18564) and related issues linked in its discussion.

---

<div class="post-metadata">

**Author:** ![pcercuei](https://discourse.cmake.org/user_avatar/discourse.cmake.org/pcercuei/32/2133_2.png) [@pcercuei](https://discourse.cmake.org/u/pcercuei)\
**Post date:** [January 31, 2022, 10:24am UTC](https://discourse.cmake.org/t/imported-link-interface-languages-property-is-ignored/4909/7 "2022-01-31T10:24:38Z")

</div>

Hi Brad,

What’s the way forward then?

Cheers,  
-Paul

---

<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:** [January 31, 2022, 4:49pm UTC](https://discourse.cmake.org/t/imported-link-interface-languages-property-is-ignored/4909/8 "2022-01-31T16:49:12Z")

</div>

For libxml2, its `libxml2-config.cmake` file needs to be fixed as I described above.

This is primarily a problem in Find modules because we don’t know what kind of artifacts will be assigned to the imported targets. That’s what the CMake Issues I linked are about. See discussion in those issues about possible paths forward for CMake itself. However, AFAIK no one is working on them right now.

Projects can set the [LINKER\_LANGUAGE](https://cmake.org/cmake/help/v3.22/prop_tgt/LINKER_LANGUAGE.html) target property on a target that has C sources in order to force linking as CXX.
