我正在尝试将一些东西添加到使用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?
解决方法
在基本的CMake发行版中有FindImageMagick.cmake模块,所以你很幸运.
你应该把这样的东西添加到CMakeLists.txt:
你应该把这样的东西添加到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})
原文地址:https://www.jb51.cc/c/116689.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。