CMake on Linux: “target platform does not support dynamic linking”

霸气de小男生 提交于 2019-12-06 20:24:35

问题


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.


回答1:


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.




回答2:


PROJECT sets some important variables about the plarform.

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



来源:https://stackoverflow.com/questions/12264299/cmake-on-linux-target-platform-does-not-support-dynamic-linking

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!