在 VC 中编译 IJG JPEG 函数库

本文详细介绍如何修改JPEG库源文件以避免与Windows头文件冲突,并完成库的编译过程。此外,还提供了如何将JPEG库集成到项目中的步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第一步:修改一些IGC源文件

/******************* Changes to jpeglib.h **************************/
#ifndef JPEGLIB_H
#define JPEGLIB_H

/* HJH modification: added extern "C" { when __cplusplus detected */
#ifdef __cplusplus
extern "C" {
#endif

...

/* near bottom of the file */
/* HJH modification: add closing } for extern "C" {  */
#ifdef __cplusplus
}
#endif

#endif /* JPEGLIB_H */

/******************* Changes to jmorecfg.h **************************/
/* jmorecfg.h line 160 */
/* X11/xmd.h correctly defines INT32 */
/* HJH modification: jmorecfg.h already contained a test for XMD_H and xmd.h
   My change adds a test for _BASETSD_H_ because the windows header file
   basestd.h already defines INT32 */
#if !defined(XMD_H) && !defined(_BASETSD_H_)
typedef long INT32;
#endif

/* jmorecfg.h line 220 */
/* HJH modification: several of the windows header files already define FAR
   because of this, the code below was changed so that it only tinkers with
   the FAR define if FAR is still undefined */
#ifndef FAR
  #ifdef NEED_FAR_POINTERS
  #define FAR  far
  #else
  #define FAR
  #endif
#endif
最后需要修改jconfig.h文件
/* HJH Note: Here is one key addition that I had to make. The jpeg library uses
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ typedef unsigned char boolean; #endif #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */

* a type called boolean. It defines boolean here. However, RPCNDR.H * yet another Microsoft header, also defines boolean. The ifndef * ensures that we don't attempt to redefine boolean if rpcndr.h has * already defined it. Note that we use unsigned char instead of int * like jmorecfg.h does, because we want to match what's in the SDK * header. See jconfig.vc for more info, it does the same thing. */

第二步:编译(来自IGP解压后的文件夹中的install.doc):
1. Copy jconfig.vc to jconfig.h, makelib.ds to jpeg.mak, and
   makeapps.ds to apps.mak. (Note that the renaming is critical!)
2. Click on the .mak files to construct project workspaces.
   (If you are using DevStudio more recent than 4.2, you'll probably
   get a message saying that the makefiles are being updated.)
3. Build the libr
ary project, then the applications project.
4. Move the application .exe files from `app`/Release to an
   appropriate location on your path.
5. To perform the self-test, execute the command line
    NMAKE /f makefile.vc test
实际上只需要执行前三步就可以。在release文件夹中可以得到最后编译的结果jpeg.lib库文件。

第三步:在自己的代码中包含
#pragma comment(lib, "jpeg.lib")

#i nclude "jpeglib.h"

Done!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值