gpt4 book ai didi

c - 带 Cmake 的 ImageMagic 库 : linking error

转载 作者:太空宇宙 更新时间:2023-11-04 04:28:08 25 4
gpt4 key购买 nike

我正在用 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();
}

在构建时我得到这个错误:

Scanning dependencies of target main
[ 33%] Building C object CMakeFiles/main.dir/main.c.o
[ 66%] Linking C executable main
CMakeFiles/main.dir/main.c.o: nella funzione "convert_image":
/home/emanuele/ClionProjects/WebServer/main.c:14: riferimento non definito a "MagickWandGenesis"
/home/emanuele/ClionProjects/WebServer/main.c:16: riferimento non definito a "NewMagickWand"
/home/emanuele/ClionProjects/WebServer/main.c:19: riferimento non definito a "MagickReadImage"
/home/emanuele/ClionProjects/WebServer/main.c:22: riferimento non definito a "MagickSetImageCompressionQuality"
/home/emanuele/ClionProjects/WebServer/main.c:25: riferimento non definito a "MagickWriteImage"
/home/emanuele/ClionProjects/WebServer/main.c:28: riferimento non definito a "DestroyMagickWand"
/home/emanuele/ClionProjects/WebServer/main.c:30: riferimento non definito a "MagickWandTerminus"
collect2: error: ld returned 1 exit status
make[3]: *** [main] Errore 1
make[2]: *** [CMakeFiles/main.dir/all] Errore 2
make[1]: *** [CMakeFiles/main.dir/rule] Errore 2
make: *** [main] Errore 2

ImageMagick 已正确安装并通过命令行运行。如何解决?

最佳答案

在您的情况下,您会收到链接器错误,因为 find_package找不到库的配置。

find_package查找格式为 <name>Config.cmake 的文件或 <lower-case-name>-config.cmake这将设置必要的变量。

不是每个库都有这些文件,如果没有,您必须在 target_link_library(...) 和其他配置中手动指定库名称(如库路径和包含路径等,如有必要)

关于c - 带 Cmake 的 ImageMagic 库 : linking error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39387108/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com