【问题标题】:unresolved external symbol _png_init_io referenced in function _pixReadStreamPng函数 _pixReadStreamPng 中引用的未解析外部符号 _png_init_io
【发布时间】:2017-09-18 11:58:31
【问题描述】:

在Windows 7下,我已经下载并解压leptonica.zip,然后按照步骤(为了成功运行Cmake):

cd leptonica
mkdir build
cd build
set PATH=%PATH%;C:\OCR\additionalLibs\zlib-1.2.8\build\Debug;C:\OCR\additionalLibs\zlib-1.2.8\build;C:\OCR\additionalLibs\zlib-1.2.8
set PATH=%PATH%;C:\OCR\additionalLibs\lpng143;C:\OCR\additionalLibs\lpng143\build\Debug;C:\OCR\additionalLibs\lpng143\build
cmake ..

之后,我得到:

-- Building for: Visual Studio 14 2015
-- The C compiler identification is MSVC 19.0.24213.1
-- The CXX compiler identification is MSVC 19.0.24213.1
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio
14.0/VC/bin/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio
14.0/VC/bin/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studi
o 14.0/VC/bin/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studi
o 14.0/VC/bin/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Could NOT find GIF (missing:  GIF_LIBRARY GIF_INCLUDE_DIR)
-- Could NOT find JPEG (missing:  JPEG_LIBRARY)
-- Found ZLIB: C:/OCR/additionalLibs/zlib-1.2.8/build/Debug/zlibd.lib (found ver
sion "1.2.8")
-- Found PNG: C:/OCR/additionalLibs/lpng143/build/Debug/png14d.lib (found versio
n "1.4.3")
-- Could NOT find TIFF (missing:  TIFF_LIBRARY TIFF_INCLUDE_DIR)
-- Found PkgConfig: C:/Program Files/CMake/bin/pkg-config.exe (found version "0.
26")
-- Checking for module 'libwebp'
--   No package 'libwebp' found
-- Checking for module 'libopenjp2'
--   No package 'libopenjp2' found
-- Looking for include file dlfcn.h
-- Looking for include file dlfcn.h - not found
-- Looking for include file inttypes.h
-- Looking for include file inttypes.h - found
-- Looking for include file memory.h
-- Looking for include file memory.h - found
-- Looking for include file stdint.h
-- Looking for include file stdint.h - found
-- Looking for include file stdlib.h
-- Looking for include file stdlib.h - found
-- Looking for include file strings.h
-- Looking for include file strings.h - not found
-- Looking for include file string.h
-- Looking for include file string.h - found
-- Looking for include file sys/stat.h
-- Looking for include file sys/stat.h - found
-- Looking for include file sys/types.h
-- Looking for include file sys/types.h - found
-- Looking for include file unistd.h
-- Looking for include file unistd.h - not found
-- Looking for include file openjpeg-2.0/openjpeg.h
-- Looking for include file openjpeg-2.0/openjpeg.h - not found
-- Looking for include file openjpeg-2.1/openjpeg.h
-- Looking for include file openjpeg-2.1/openjpeg.h - not found
-- Looking for include file openjpeg-2.2/openjpeg.h
-- Looking for include file openjpeg-2.2/openjpeg.h - not found
-- Looking for fmemopen
-- Looking for fmemopen - not found
-- Check if the system is big endian
-- Searching 16 bit integer
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of unsigned short
-- Check size of unsigned short - done
-- Using unsigned short
-- Check if the system is big endian - little endian
-- Configuring done
-- Generating done
-- Build files have been written to: C:/OCR/leptonica-master/build

故意不考虑libjpeg、libtiff 和libgif,因为我只对管理png 文件感兴趣。 cmake 命令输出一个leptonica.sln 解决方案文件。 然后我在visual studio上编译解决方案文件(为了找到头文件zlib.h ; zconf.h; png.h; pngconfig.h我修改了INCLUDE目录,添加:C:\OCR\additionalLibs\zlib-1.2.8;C:\OCR\additionalLibs\lpng143 )。

但由于错误,解决方案无法编译:

LNK2019 unresolved external symbol _png_init_io referenced in function _pixReadStreamPng    leptonica   
LNK2019 unresolved external symbol _png_init_io referenced in function _pixReadStreamPng    leptonica

错误来自文件 pngio.h ,它在 pixReadStreamPng 中调用函数 png_init_io ,在 png.h 中定义。似乎找不到该功能的实现,是否还有其他应该实现的库? png_init_io在哪里实现?

【问题讨论】:

  • 在 png.c 中实现。但它由#ifdef PNG_STDIO_SUPPORTED 保护,您可能没有定义它。参见 png.c 中的 cmets
  • @GlennRanders-Pehrson 请把它写成答案,它为我解决了问题! =) 非常感谢
  • 很抱歉再次提出这个问题,但解决方法是什么?我在导入之前尝试在我的文件中#define PNG_STDIO_SUPPORTED 1,但它仍然无法正常工作

标签: windows visual-c++ libpng leptonica


【解决方案1】:

它在 libpng 的 png.c 中实现,但它由 #ifdef PNG_STDIO_SUPPORTED 保护,您可能没有定义它。参见 png.c 中的 cmets:

#  ifdef PNG_STDIO_SUPPORTED
/* Initialize the default input/output functions for the PNG file.  If you
 * use your own read or write routines, you can call either png_set_read_fn()
 * or png_set_write_fn() instead of png_init_io().  If you have defined
 * PNG_NO_STDIO or otherwise disabled PNG_STDIO_SUPPORTED, you must use a
 * function of your own because "FILE *" isn't necessarily available.
 */
void PNGAPI
png_init_io(png_structrp png_ptr, png_FILE_p fp)
{
   png_debug(1, "in png_init_io");

   if (png_ptr == NULL)
      return;

   png_ptr->io_ptr = (png_voidp)fp;
}
#  endif

【讨论】:

    【解决方案2】:

    您必须在 CMake 配置中取消选中 PNG_NO_STDIO 标志

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-04
      • 1970-01-01
      • 1970-01-01
      • 2020-02-15
      相关资源
      最近更新 更多