我正在尝试将一些东西添加到使用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})