[CMake] (no subject)

Dan Liew dan at su-root.co.uk
Fri May 22 08:19:10 EDT 2015


Hi,

On 21 May 2015 at 23:00,  <Lucas.Pettey at engilitycorp.com> wrote:
> Hello,
>
> I am trying to compile a code written in C, but using an external library
> that contains C++ functions. I am on a Cray system and everything works if I
> manually link with the cray CC wrapper. When I change the linker language
> with this command:
>
> set_property(TARGET adh PROPERTY LINKER_LANGUAGE CXX)
>
> CMake is using the CC wrapper, but adding -lstdc++ to the link line. This
> causes an error. Can anyone tell me how to not get this added library?

Why are you telling CMake that the linker language is C++ in the
target you are building is C code? The C code you are compiling be
must calling into extern "C" functions in the external library you
mention which means the linker (at compile time) should not need to
know about C++ at all. At runtime the linker needs to know that your
external library depends on C++ but you don't need to be concerned
with this because when your external library was built those
dependencies end up in the shared library.

E.g.

```
$ readelf -d /usr/lib/libboost_program_options.so
...
  Tag        Type                         Name/Value
...
0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
...
```

Does your target build if you just leave  LINKER_LANGUAGE alone (i.e.
set C)? I would expect that it would.

Thanks,
Dan.


More information about the CMake mailing list