将 ImageMagick 库的 ImageWand 组件与 CMake 一起使用
Use ImageWand component of ImageMagick lib with CMake
我正在用 C 编程。我想使用 ImageMagick 库,但有些功能无法解析。
这是我的 cMakeList.txt 文件:
cmake_minimum_required(VERSION 3.3)
project(WebServer)
set(CMAKE_C_COMPILER "/usr/bin/gcc")
set(SOURCE_FILES io.c server.c lock_fcntl.c sig_handler.c thread_job.c msg_parser.c)
set(LIB http-parser-master/http_parser.c )
set(CMAKE_USE_PTHREADS_INIT true)
set(CMAKE_USE_PTHREADS_INIT ON)
find_package(Threads REQUIRED)
find_package(ImageMagick COMPONENTS ImageWand)
include_directories(header)
include_directories(http-parser-master)
#include_directories(/usr/local/include/ImageMagick-7/MagickWand)
include_directories(${ImageMagick_INCLUDE_DIRS})
add_executable(server ${SOURCE_FILES} ${LIB})
add_executable(client client.c io.c)
add_executable(main main.c io.c)
target_link_libraries(main ${ImageMagick_LIBRARIES})
target_link_libraries(server Threads::Threads)
这是来源main.c:
#include <ImageMagick-7/MagickWand/MagickWand.h>
#include "basic.h"
void convert_image(char *path, float quality_factor, char *out) {
int width, height;
MagickWand *n_wand = NULL;
MagickWandGenesis();
m_wand = (struct MagickWand *) NewMagickWand();
MagickReadImage(m_wand,"logo:");
width = MagickGetImageWidth(m_wand);
height = MagickGetImageHeight(m_wand);
if((width /= 2) < 1)width = 1;
if((height /= 2) < 1)height = 1;
MagickResizeImage(m_wand,width,height,LanczosFilter,1);
MagickSetImageCompressionQuality(m_wand,95);
MagickWriteImage(m_wand,"logo_resize.jpg");
if(m_wand)m_wand = (struct MagickWand *) DestroyMagickWand(m_wand);
MagickWandTerminus();
}
只有 MagickWandGenesis()
和 MagickWandTerminus()
得到解决。
库的安装正确结束。如何解决?
编辑:
运行 我收到错误:
/usr/local/include/ImageMagick-7/MagickWand/MagickWand.h:29:40: fatal error: MagickCore/magick-config.h: File o directory non esistente
# include "MagickCore/magick-config.h"
^
compilation terminated.
make[3]: *** [CMakeFiles/main.dir/main.c.o] Errore 1
make[2]: *** [CMakeFiles/main.dir/all] Errore 2
make[1]: *** [CMakeFiles/main.dir/rule] Errore 2
make: *** [main] Errore 2
我尝试了此处显示的解决方案但不起作用:
ImageMagick No such file or directory
库结构是:
ImageMagick-7
├── MagickCore
│ ├── magick-config.h
|
└── MagickWand
├── MagickWand.h
MagickWand.h
在 MagickCore 中包含一些 header。
我修复替换 include_directories(${ImageMagick_INCLUDE_DIRS})
include_directories(/usr/local/include/ImageMagick-7)
。
我不知道为什么,但如果我打印 ${ImageMagick_INCLUDE_DIRS}
这未设置。
我正在用 C 编程。我想使用 ImageMagick 库,但有些功能无法解析。
这是我的 cMakeList.txt 文件:
cmake_minimum_required(VERSION 3.3)
project(WebServer)
set(CMAKE_C_COMPILER "/usr/bin/gcc")
set(SOURCE_FILES io.c server.c lock_fcntl.c sig_handler.c thread_job.c msg_parser.c)
set(LIB http-parser-master/http_parser.c )
set(CMAKE_USE_PTHREADS_INIT true)
set(CMAKE_USE_PTHREADS_INIT ON)
find_package(Threads REQUIRED)
find_package(ImageMagick COMPONENTS ImageWand)
include_directories(header)
include_directories(http-parser-master)
#include_directories(/usr/local/include/ImageMagick-7/MagickWand)
include_directories(${ImageMagick_INCLUDE_DIRS})
add_executable(server ${SOURCE_FILES} ${LIB})
add_executable(client client.c io.c)
add_executable(main main.c io.c)
target_link_libraries(main ${ImageMagick_LIBRARIES})
target_link_libraries(server Threads::Threads)
这是来源main.c:
#include <ImageMagick-7/MagickWand/MagickWand.h>
#include "basic.h"
void convert_image(char *path, float quality_factor, char *out) {
int width, height;
MagickWand *n_wand = NULL;
MagickWandGenesis();
m_wand = (struct MagickWand *) NewMagickWand();
MagickReadImage(m_wand,"logo:");
width = MagickGetImageWidth(m_wand);
height = MagickGetImageHeight(m_wand);
if((width /= 2) < 1)width = 1;
if((height /= 2) < 1)height = 1;
MagickResizeImage(m_wand,width,height,LanczosFilter,1);
MagickSetImageCompressionQuality(m_wand,95);
MagickWriteImage(m_wand,"logo_resize.jpg");
if(m_wand)m_wand = (struct MagickWand *) DestroyMagickWand(m_wand);
MagickWandTerminus();
}
只有 MagickWandGenesis()
和 MagickWandTerminus()
得到解决。
库的安装正确结束。如何解决?
编辑:
运行 我收到错误:
/usr/local/include/ImageMagick-7/MagickWand/MagickWand.h:29:40: fatal error: MagickCore/magick-config.h: File o directory non esistente
# include "MagickCore/magick-config.h"
^
compilation terminated.
make[3]: *** [CMakeFiles/main.dir/main.c.o] Errore 1
make[2]: *** [CMakeFiles/main.dir/all] Errore 2
make[1]: *** [CMakeFiles/main.dir/rule] Errore 2
make: *** [main] Errore 2
我尝试了此处显示的解决方案但不起作用: ImageMagick No such file or directory
库结构是:
ImageMagick-7
├── MagickCore
│ ├── magick-config.h
|
└── MagickWand
├── MagickWand.h
MagickWand.h
在 MagickCore 中包含一些 header。
我修复替换 include_directories(${ImageMagick_INCLUDE_DIRS})
include_directories(/usr/local/include/ImageMagick-7)
。
我不知道为什么,但如果我打印 ${ImageMagick_INCLUDE_DIRS}
这未设置。