freeImage静态库连接

本文介绍了如何在C++项目中使用FreeImage静态库而非DLL。关键步骤包括:确保编译时C/C++代码生成的运行时库设置一致,添加预定义宏FREEIMAGE_LIB,将编译得到的lib文件放置在链接器可以找到的位置,并在编译器和链接器设置中进行相应配置。

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

for new coder  通过搜索关键词进来的,希望能起一点参考作用

当然,如果使用dll就简单许多,但我对于附带一个dll这种行为很不爽,于是想用静态库连接一下

在大概弄明白原理之后就下源码,选择静态库编译,然后分别得到debug 和 release 的 lib,再使用

#ifdef _DEBUG
#pragma comment(lib,"FreeImageD.lib")
#else
#pragma comment(lib,"FreeImage.lib")
#endif
链接到程序里,结果嘛肯定是报错了,然后就开始了漫长的排错之旅 ,不想写成记叙文了,简单说要点吧
1 如果在编译lib库时项目属性的c/c++ 代码生成的运行时库的debug和release 选择 /MDd 和/MD  自己工程也要这么设置才可以正确连接

2 在预定义宏的部分加上 FREEIMAGE_LIB

完成上面两点的修正才可以正确链接,如果仍有问题 请观看官方因为说明,本人就是因为太急了才绕了一个很大的圈,
提醒自己一下 下次使用类似的开源库一定要看说明

How to use FreeImage as a static library instead of as a DLL (Visual C++ 6) ?
Using FreeImage as a static library is not so easy, but it's not more complicated than using any other library. Here is a step by step method to do this :
1. Compile the FreeImage library in debug and release modes and close your projects. You won't need to use the FreeImage source code anymore.
Note: Do not compile the FreeImage DLL (project named FreeImage) but the project named FreeImageLib. This should produce a huge file named FreeImage.lib (in release mode) or FreeImaged.lib (in debug mode) in the Dist/ directory.
 
2. Copy FreeImage.lib/FreeImaged.lib into your lib/ directory or in a directory where the linker can find them (e.g. your project directory). You can use "Menu->Tools->Options->Directories->Library files" for this.
 
3. Create a new project and add your code in it.
Add a call to FreeImage_Initialise() at the beginning of you main function and a call to FreeImage_DeInitialise() at the end of this function.
 
4. Edit the compiler options (Menu -> Project -> Settings)
1. tab C/C++ : Category "Preprocessor"
* Add FREEIMAGE_LIB to the preprocessor definitions
2. tab C/C++ : Category "Code Generation"
* Use the Multithreaded run-time library (in release mode)
* Use the Debug Multithreaded run-time library (in debug mode)

5. Edit linker options (Menu -> Project -> Settings)         (第五条没用到,因为没找到选项,可能只是和vc6.0有关)
1. tab Link : Category Input
* Add FreeImage.lib to the list of object/library modules (release mode)
* Add FreeImaged.lib to the list of object/library modules (debug mode)
2. tab Link : Category Input
* Add LIBCMT to the Ignore library list (it helps to avoid a warning)

6. Compile and link your program.

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值