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.