boo*_*y81 8 c++ imagemagick cmake
我正在尝试将一些东西添加到使用CMake开发的更大的C++项目中.在我添加的部分中,我想使用Magick ++.
如果我只编译我的小示例程序
#include <Magick++.h>
int main()
{
Magick::Image image;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
同
g++ -o example example.cxx
Run Code Online (Sandbox Code Playgroud)
它失败了,因为它找不到"Magick ++.h".
如果我正在使用
g++ -I /usr/include/ImageMagick -o example example.cxx
Run Code Online (Sandbox Code Playgroud)
我得到"未定义的引用"错误.
如果我按照http://www.imagemagick.org/script/magick++.php上的说明进行编译并使用
g++ `Magick++-config --cxxflags --cppflags` -o example example.cxx `Magick++-config --ldflags --libs`
Run Code Online (Sandbox Code Playgroud)
有用.
现在:如何将其合并到使用CMake的大型项目中?我如何更改CMakeLists.txt?
arr*_*owd 18
在基本的CMake发行版中有FindImageMagick.cmake模块,所以你很幸运.你应该把这样的东西添加到CMakeLists.txt:
find_package(ImageMagick COMPONENTS Magick++)
Run Code Online (Sandbox Code Playgroud)
之后,您可以使用以下变量:
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
Run Code Online (Sandbox Code Playgroud)
所以你可以做到
include_directories(${ImageMagick_INCLUDE_DIRS})
target_link_libraries(YourApp ${ImageMagick_LIBRARIES})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3926 次 |
| 最近记录: |