CMake on Linux: "target platform does not support dynamic linking"
Asked Answered
O

2

25

I have the very simple CMakeLists.txt

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
FIND_PACKAGE(VTK REQUIRED)
PROJECT(test CXX)

that really doesn't do anything. The package VTK is correctly found under /usr/lib/vtk-5.8/VTKConfig.cmake. This file includes a number of statements of the type

ADD_LIBRARY(foobar SHARED IMPORTED)

to indicate that the shared library libfoobar.so will need to be linked in executables.

Upon creating Makefiles using the above script, however, CMake will complain that

CMake Warning (dev) at /usr/lib/vtk-5.8/VTKTargets.cmake:244 (ADD_LIBRARY):
  ADD_LIBRARY called with SHARED option but the target platform does not
  support dynamic linking.  Building a STATIC library instead.  This may lead
  to problems.
Call Stack (most recent call first):
  /usr/lib/vtk-5.8/VTKConfig.cmake:200 (INCLUDE)
  /usr/share/cmake-2.8/Modules/FindVTK.cmake:73 (FIND_PACKAGE)
  CMakeLists.txt:4 (FIND_PACKAGE)
This warning is for project developers.  Use -Wno-dev to suppress it

What does this warning mean and how is it dealt with?

This is a Linux system with CMake 2.8.9. While this error message appears for all packages that contain ADD_LIBRARY(foobar SHARED IMPORTED), VTK-5.8 is used as an example here.

Olfe answered 4/9, 2012 at 13:15 Comment(0)
M
54

PROJECT sets some important variables about the plarform.

Don't call FIND_* modules before setting a name to PROJECT.

Maupin answered 15/9, 2014 at 9:2 Comment(2)
Great answer, however not applicable in case the FIND_* command is in a toolchain file. See cmake.org/Bug/view.php?id=15999Monolithic
This helped me out, I am using QT and called find_package before project, I flipped them and the error went away.Mesitylene
T
13

This error message occurs when the CMake global property TARGET_SUPPORTS_SHARED_LIBS is set false and you use a shared library. See Source/cmAddLibraryCommand.cxx line 100 in the CMake source.

This shouldn't normally occur unless you are cross compiling for a very basic system (embedded OS).

I suspect that either this is a bug in the latest version of CMake or you have not configured CMake correctly.

Thug answered 4/9, 2012 at 14:56 Comment(1)
Indeed. For some reason, TARGET_SUPPORTS_SHARED_LIBS isn't set on this Linux machine here. Explicitly setting SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE) does away with the warnings.Carvajal

© 2022 - 2024 — McMap. All rights reserved.