cmake中添加引用动态链接_Linux上的CMake:“目标平台不支持动态链接”

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.

解决方案

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.


版权声明:本文为weixin_34260787原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。