我一直在努力让libJPEG 9b在我的Visual Studio Community 2017项目上工作。我尝试过几种方法:
我正在尝试给出here的代码。 现在,我似乎得到了一堆链接错误。
1>------ Build started: Project: JpegReadWrite, Configuration: Debug x64 ---
1>JpegReadWrite.obj : error LNK2019: unresolved external symbol jpeg_std_error referenced in function main
1>JpegReadWrite.obj : error LNK2019: unresolved external symbol jpeg_CreateDecompress referenced in function main
1>JpegReadWrite.obj : error LNK2019: unresolved external symbol jpeg_destroy_decompress referenced in function main
1>JpegReadWrite.obj : error LNK2019: unresolved external symbol jpeg_mem_src referenced in function main
1>JpegReadWrite.obj : error LNK2019: unresolved external symbol jpeg_read_header referenced in function main
1>JpegReadWrite.obj : error LNK2019: unresolved external symbol jpeg_start_decompress referenced in function main
1>JpegReadWrite.obj : error LNK2019: unresolved external symbol jpeg_read_scanlines referenced in function main
1>JpegReadWrite.obj : error LNK2019: unresolved external symbol jpeg_finish_decompress referenced in function main
1>D:\tonbo_stuti\libjpeg\jpeg-build\lib\libjpeg.a : warning LNK4272: library machine type 'X86' conflicts with target machine type 'x64'
1>C:\Users\tonbo\Documents\Visual Studio 2017\Projects\serverAppl\x64\Debug\JpegReadWrite.exe : fatal error LNK1120: 8 unresolved externals 1>Done building project "JpegReadWrite.vcxproj" -- FAILED.
我对如何使libJPEG工作并且不了解正在发生的事情感到非常困惑,因为我是Visual Studio环境的新手。我检查过这些符号实际上是在“jpeglib.h”中定义的,我已经包含了这些符号。我认为我可以为.a文件执行与.lib文件相同的步骤,但是出了点问题。
我真的很感激任何帮助。
答案 0 :(得分:1)
您需要使用相同的目标,即libjpeg x64。
如果您想使用MingW,我建议您执行以下操作:
MSys2-x64的基本安装没有任何构建工具链。为了编译x86和x86_64,我们需要手动为i686和x86_64安装工具链。
因此,请执行MSys-Shell实例中的后续步骤:
#! /bin/bash
if [ "${MSYSTEM}" != "MINGW32" ]; then
echo "You must run this script from a MingW32 shell!"
exit;
fi
PWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TGT=${PWD}/deploy/Win32
mkdir -p ${TGT}/include
mkdir -p ${TGT}/lib
mkdir -p ${TGT}/bin
mkdir -p ${TGT}/man/man1
./configure static --prefix=${TGT} --exec-prefix=${TGT} --
includedir=${TGT}/include --libdir=${TGT}/lib
echo "----------- CLEAN -----------"
make clean
echo "----------- MAKE -----------"
make
echo "----------- INSTALL -----------"
make install
echo "----------- INSTALL-LIB -----------"
make install-lib
echo "----------- INSTALL-HEADERS -----------"
make install-headers
echo "----------- CHECKING OUTPUT -----------"
objdump -f ${TGT}/lib/libjpeg.a | grep "file format"

使用" mingw64.exe "做同样的事情,但是:
使用MSys2和MingW工具链交叉编译非常棒,你应该同时拥有:x86和x86_64 libjpegs。
最终的objdump应该显示正确的架构。 E.g:
// x86 output
jcapimin.o: file format pe-i386
jcapistd.o: file format pe-i386
jctrans.o: file format pe-i386
jcparam.o: file format pe-i386
jdatadst.o: file format pe-i386
// ...
// x64 output
jcapimin.o: file format pe-x86-64
jcapistd.o: file format pe-x86-64
jctrans.o: file format pe-x86-64
jcparam.o: file format pe-x86-64
jdatadst.o: file format pe-x86-64
// ...

最后,您必须链接到deploy / Win32 / lib或deploy / Win64 / lib中的相应lib。
我在自己的机器上进行了测试,它有两个精心构建的libjpeg.a:D