[CMake] Redundant linking when modifying shared libraries

Robert Maynard robert.maynard at kitware.com
Thu Feb 14 13:07:44 EST 2019


> I wonder why this isn't the default behavior

By default CMake wants to get a correct build 100% of the time. There
is nothing to stop people from having functions defined in a .cxx file
with no corresponding header, and using manual forward deceleration is
used in a consuming library/executable. By setting
`LINK_DEPENDS_NO_SHARED` to `True` you will convert what was a link
time error ( renaming the function in the .cxx ) to a run time error.

On Thu, Feb 14, 2019 at 12:11 PM Itay Chamiel <itay.chamiel at orcam.com> wrote:
>
> On Thu, Feb 14, 2019 at 12:39 PM Craig Scott <craig.scott at crascit.com> wrote:
> > I think you might be looking for the LINK_DEPENDS_NO_SHARED target property (or more likely its associated CMAKE_LINK_DEPENDS_NO_SHARED variable).
>
> After my previous response I experimented a little more, and I got it
> to work. My mistake was that I needed to add the configuration line to
> the executable target, not the lib. So in my example, add the
> following line to the Demo/CMakeLists.txt file:
>
> set_target_properties(helloDemo PROPERTIES LINK_DEPENDS_NO_SHARED true)
>
> ..and it works like a charm. I wonder why this isn't the default
> behavior; can you think of any scenario where this would produce
> invalid results?
>
> Thanks for your help!
>
> itay
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> https://cmake.org/mailman/listinfo/cmake


More information about the CMake mailing list