VC6下编译IJG库
IJG 是什么?
IJG 是一个处理 jpeg 的 C 语言写的库,其官方站点是 http://www.ijg.org/。
http://www.ijg.org/ 写道
Independent JPEG Group
IJG is an informal group that writes and distributes a widely used free library for JPEG image compression. The first version was released on 7-Oct-1991.
The current version is release 8d of 15-Jan-2012. This is a stable and solid foundation for many application's JPEG support.
You can find our code and some supporting documentation in the directory files. There is a Unix format package in tar.gz archive format jpegsrc.v8d.tar.gz and a Windows format package in zip archive format jpegsr8d.zip.
To learn more about how to use JPEG, see the JPEG FAQ. If you'd like to learn about how JPEG works, start with the comp.compression FAQ.
The ISO/IEC JTC1/SC29/WG1 standards committee (also known as JPEG, together with ITU-T SG16) has their own web site. IJG is not affiliated with the ISO committee.
IJG development continues. Advanced features are being prepared for coming releases...
Version 9 of the Independent JPEG Group software is currently in development and is planned for release in January 2013. The development site for IJG JPEG 9 is at InfAI.org.
怎么编译 jpeg.lib ?
下载 jpegsr8d.zip 文件之后解压,打开其中的 install.txt 文件,找到文件末尾的关于 VC6 的编译指令说明,如下:
install.txt 写道
Microsoft Windows, Microsoft Visual C++ 6 Developer Studio:
We include makefiles that should work as project files in DevStudio 6.0 or
later. There is a library makefile that builds the IJG library as a static
Win32 library, and application makefiles that build the sample applications
as Win32 console applications. (Even if you only want the library, we
recommend building the applications so that you can run the self-test.)
To use:
1. Open the command prompt, change to the main directory and execute the
command line
NMAKE /f makefile.vc setup-vc6
This will move jconfig.vc to jconfig.h and makefiles to project files.
(Note that the renaming is critical!)
2. Open the workspace file jpeg.dsw, build the library project.
(If you are using DevStudio more recent than 6.0, you'll probably
get a message saying that the project files are being updated.)
3. Open the workspace file apps.dsw, build the application projects.
4. To perform the self-test, execute the command line
NMAKE /f makefile.vc test-build
5. Move the application .exe files from `app`\Release to an
appropriate location on your path.
D:\test\jpegsr8d\jpeg-8d>NMAKE /f makefile.vc setup-vc6
Microsoft (R) Program Maintenance Utility Version 6.00.8168.
Copyright (C) Microsoft Corp 1988-1998. All rights reserved.
ren jconfig.vc jconfig.h
ren makejdsw.vc6 jpeg.dsw
ren makeadsw.vc6 apps.dsw
ren makejmak.vc6 jpeg.mak
ren makejdep.vc6 jpeg.dep
ren makejdsp.vc6 jpeg.dsp
ren makecmak.vc6 cjpeg.mak
ren makecdep.vc6 cjpeg.dep
ren makecdsp.vc6 cjpeg.dsp
ren makedmak.vc6 djpeg.mak
ren makeddep.vc6 djpeg.dep
ren makeddsp.vc6 djpeg.dsp
ren maketmak.vc6 jpegtran.mak
ren maketdep.vc6 jpegtran.dep
ren maketdsp.vc6 jpegtran.dsp
ren makermak.vc6 rdjpgcom.mak
ren makerdep.vc6 rdjpgcom.dep
ren makerdsp.vc6 rdjpgcom.dsp
ren makewmak.vc6 wrjpgcom.mak
ren makewdep.vc6 wrjpgcom.dep
ren makewdsp.vc6 wrjpgcom.dsp
D:\test\jpegsr8d\jpeg-8d>
上面的步骤会在源程序目录中生成很多 dsp 和 dsw 文件,选择其中的 jpeg.dsw 用 VC6 打开。
编译之后就会在 Release 目录生成 jpeg.lib 静态库文件。
怎样在 VC6 中使用 IJG 的 jpeg 库?
为了方便以后使用,可创建一个名为 libjpeg 的目录,将下列文件复制到其中:
jpeg.lib
jpeglib.h
jconfig.h
jmorecfg.h
以后在使用的时候就只需要将 libjpeg 目录复制到工程所在目录中,与 jpeg-8d 下一大堆文件无关了。
在使用时,使用到该库的 cpp 文件应加上如下内容:
extern "C" {
#include "jpeglib.h"
}
#pragma comment(lib, "libjpeg/jpeg.lib")
因为那些头文件是放置在 libjpeg 目录中的,因此需要增加 附加包含路径 libjpeg,操作如下:
在菜单“工程”中选择“设置”,切到“C/C++”,将“分类”选择为“预处理器”,在“附加包含路径”中加入 libjpeg 。
使用时需要 将 MFC 库作为静态库使用,更改方式:
在菜单“工程”中选择“设置”,切到“常规”,就会看到 Microsoft 基础类的设置,改成“把MFC作为静态链接库”。
否则,在链接时报一大堆错误
编译连接出错信息 写道
Linking...
libcmt.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrtd.lib(MSVCRTD.dll)
libcmt.lib(crt0dat.obj) : error LNK2005: __exit already defined in msvcrtd.lib(MSVCRTD.dll)
libcmt.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in msvcrtd.lib(cinitexe.obj)
libcmt.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in msvcrtd.lib(cinitexe.obj)
libcmt.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in msvcrtd.lib(cinitexe.obj)
libcmt.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in msvcrtd.lib(cinitexe.obj)
libcmt.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in msvcrtd.lib(MSVCRTD.dll)
msvcrtd.lib(MSVCRTD.dll) : error LNK2005: __setmbcp already defined in libcmt.lib(mbctype.obj)
LINK : warning LNK4098: defaultlib "msvcrtd.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
msvcrtd.lib(cinitexe.obj) : warning LNK4098: defaultlib "libcmt.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
libcmt.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/TestClipboard.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.
参考资料
参考资料1:vc++6.0环境下编译使用IJG
http://hi.baidu.com/zhi_qiu_yi_ye/blog/item/7d367f27704aa75f9922ed05.html
参考资料2:利用IJG JPEG Library压缩图像为jpg格式
http://www.vckbase.com/document/viewdoc/?id=1790