[CMake] (no subject)

Lucas.Pettey at engilitycorp.com Lucas.Pettey at engilitycorp.com
Fri May 22 11:11:41 EDT 2015


The Cray system requires static libraries, so all symbols are defined during the linking process. 

Leaving out the LINKER_LANGUAGE CXX statement, CMake sees all the source files as C files, uses the C linker and I get undefined symbol errors. Manually linking with the C++ linker but excluding the -lstdc++ flag generates an executable.

I really just need CMake to use the C++ linker without adding that flag.

Thanks,

Lucas Pettey, PhD
HPCMP PETTT EQM CTA Lead
ERDC-DSRC OnSite
Vicksburg, MS
512-297-9833 Mobile (preferred)
601-634-2980 Office
lucas.pettey at engilitycorp.com

________________________________________
From: Dan Liew [dan at su-root.co.uk]
Sent: Friday, May 22, 2015 7:19 AM
To: Pettey, Lucas @ EngilityCorp
Cc: cmake at cmake.org
Subject: Re: [CMake] (no subject)

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