CMake BUILD 未定义引用findpng

问题描述

我对 CMake 还是很陌生,所以绝对欢迎反馈。因此,我正在尝试构建一个简单的应用程序,该应用程序最终应该使用库 libharu 创建一个 pdf。

我想我想出了如何链接库。但我仍然收到 findpng 模块的构建错误(我想 libharu 取决于它)

build

CMakeLists.txt:

cmake_minimum_required(VERSION 3.2.0 FATAL_ERROR)     # current latest stable version (if lower give FATAL_ERROR)
project(pdf_generator VERSION 0.1.0)                  # name of the project,version.

file(GLOB TARGET_SRC "./src/*.cpp")                   # Creates variable,using globbing.

include_directories(${PROJECT_SOURCE_DIR}/include)    # list of directories to be used as header search paths.
add_executable(main ${TARGET_SRC})                    # Create an executable of set of source files [exe name files to bundle].



find_library(libhpdf_location NAMES libhpdf.a)        # find the location of libhpdf.a and save the value in the variable libhpdf_location.
message(STATUS ${libhpdf_location})                   # print status of variable.

add_library(libhpdf STATIC IMPORTED)                  # Add library via a static import.
set_target_properties(
  libhpdf PROPERTIES
  IMPORTED_LOCATION ${libhpdf_location}
)

target_link_libraries(main libhpdf)

解决方法

我以前从未使用过那个特定的库,但是在 GitHub 上浏览他们的 CMakeLists.txt 似乎 libharu 对 libpdf 和 zlib 有可选的依赖项。在不知道您是如何构建 libharu 版本的情况下,我将假设两者都需要。

幸运的是,CMake 为 libpng 和 zlib 提供了查找模块,因此添加以下内容应该可以:

find_package(PNG REQUIRED)
find_package(ZLIB REQUIRED)

set_target_properties(libhpdf
  PROPERTIES
    INTERFACE_LINK_LIBRARIES "ZLIB::ZLIB;PNG::PNG"
)
,

看起来您需要做的就是告诉 cmake 链接 libpng。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...