【问题标题】:Set path in CMake (C++, ImageMagick)在 CMake 中设置路径(C++、ImageMagick)
【发布时间】:2011-12-15 17:14:39
【问题描述】:

我正在尝试向使用 CMake 开发的大型 C++ 项目添加一些内容。在我要添加的部分,我想使用 Magick++。

如果我只是编译我的小示例程序

#include <Magick++.h>

int main()
{
  Magick::Image image;

  return 0;
}

g++ -o example example.cxx

它失败了,因为它没有找到“Magick++.h”。

如果我正在使用

g++ -I /usr/include/ImageMagick -o example example.cxx

我收到“未定义的引用”错误。

如果我按照http://www.imagemagick.org/script/magick++.php 上的说明进行编译使用

g++ `Magick++-config --cxxflags --cppflags` -o example example.cxx `Magick++-config --ldflags --libs`

它有效。

现在: 如何将其合并到使用 CMake 的较大项目中?如何更改 CMakeLists.txt?

【问题讨论】:

    标签: c++ imagemagick cmake


    【解决方案1】:

    在基本的 CMake 发行版中有 FindImageMagick.cmake 模块,所以你很幸运。 您应该在 CMakeLists.txt 中添加类似这样的内容:

    find_package(ImageMagick COMPONENTS Magick++)
    

    之后,您可以使用以下变量:

    ImageMagick_FOUND                    - TRUE if all components are found.
    ImageMagick_INCLUDE_DIRS             - Full paths to all include dirs.
    ImageMagick_LIBRARIES                - Full paths to all libraries.
    ImageMagick_<component>_FOUND        - TRUE if <component> is found.
    ImageMagick_<component>_INCLUDE_DIRS - Full path to <component> include dirs.
    ImageMagick_<component>_LIBRARIES
    

    所以你可以这样做

    include_directories(${ImageMagick_INCLUDE_DIRS})
    target_link_libraries(YourApp ${ImageMagick_LIBRARIES})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-21
      相关资源
      最近更新 更多