将FreeImage链接为VS2010中的静态库? [英] Linking FreeImage as a static library in VS2010?

查看:259
本文介绍了将FreeImage链接为VS2010中的静态库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个图片库,我一直在寻找FreeImage, http://freeimage.sourceforge.net/
我想将它静态链接到我的应用程序。



我已经尝试下载二进制文件并链接它,但我得到2019链接器错误,当我尝试调用他们的函数,即使我是积极的,我链接它正确。



然后我试图下载他们的源,转换他们的FreeImageLib.2008VS2010, 。它自己构建的只是罚款,但我仍然有同样的问题,当链接到它,我的应用程序使用它仍然抱怨链接器错误。



我还将所有项目配置设置为与我的其他项目匹配,因此与/ MDd或/ MTd等没有冲突。



我做了一些挖掘他们的源和有像FREEIMAGE_LIB的宏,这表明它应该在构建静态库时定义,并且它被定义,但仍然不工作。 p>

我已经搜索过,找不到任何这个问题的固定答案。有关获取FreeImage与Visual Studio 2010一起使用的答案,没有不同;我已经在包含头或者作为预处理器参数之前定义了宏,但是它的dosnt工作。



这个库不是用作静态库,可能是问题?
有人能够在VS2010 +上静态链接FreeImage?



感谢

解决方案

是的,我已经能够链接FreeImage静态在几个Visual Studio版本。



对于FreeImage,默认情况下,我们有8个选项将它链接到你的应用程序:



FreeImage - 动态链接(您将需要dll)。



FreeImageLib - 静态链接。



因此,假设我们需要(静态& C),所有这些都可以用Debug或者Release & Win32&& amp; Debug)和(Static&&& Win32&在我们的应用程序中,我们使用动态运行时库(默认情况下,FreeImage为静态设置为某种原因)
我们通常得到它:




  • 下载并解压新版本(或至少清除旧的distib)


  • 打开 FreeImage.2008。 sln 通过Shift +单击选择10个项目中的全部。然后在项目属性/ C ++ /代码生成中,选择Debug配置的/ MDd和Release的/ MD。


  • 我们进入菜单/构建/批量构建,选择:



    FreeImageLib |调试| Win32



    FreeImageLib |版本| Win32




并按Build。




  • 等待选择配置。我们需要的所有内容都将复制到中的 FreeImage\Dist 文件夹


  • > FreeImage \Dist 文件夹检查文件:
    delete.me
    FreeImage.h
    FreeImage.lib
    FreeImaged.lib
    检查创建日期和时间。它必须新鲜烘烤和热。如果没有,请从 FreeImage\Source\FreeImageLib\Debug FreeImage\Source\FreeImageLib\Release


  • 在主应用程序中添加到include和lib FreeImage\Dist 并链接 FreeImaged.lib 到Debug配置和 FreeImage.lib 到版本。

  • 包含在源文件中:



    #define FREEIMAGE_LIB



    #includeFreeImage.h


  • 尝试呼叫
    FreeImage_Initialise();
    FreeImage_DeInitialise();


  • I need a image library and I've been looking into FreeImage, http://freeimage.sourceforge.net/. I want to link it statically with my application.

    I have tried downloading the binaries and link it with, but I get 2019 linker errors when I try to call their functions, even though I am positive I linked it correct.

    So then I tried to download their source, converted their "FreeImageLib.2008" to VS2010 and built it. It builds just fine on its own, but I still have the same problem when linking against it, my application that uses it still complaints about linker errors.

    I also set all the project configuration to match my other projects, so there is no conflict with /MDd or /MTd, etc..

    I did some digging in their source and there are macros like "FREEIMAGE_LIB" which suggests it should be defined when building a static library, and it IS defined, yet still it dosn't work.

    I've googled around and cannot find any solid answers to this issue. The answer on Getting FreeImage to work with Visual Studio 2010 makes no difference; I already defined the macro either before including the header or as a preprocessor argument but it dosnt work.

    Is this library not meant to be used as a static library, or what could possibly be the issue? Has anyone been able to link FreeImage statically on VS2010+?

    Thanks

    解决方案

    Yes, I've been able to link FreeImage statically on several Visual studio versions. Here I describe how I do this usually.

    With FreeImage, by default, we have 8 options to link it to your app:

    FreeImage - dynamic link (you will need dll).

    FreeImageLib - static link.

    Each of these can be built with "Debug" or with "Release" configurations and for Win32 or Win64 platforms.

    So, assume that we need ( Static && Win32 && Debug ) and ( Static && Win32 && Release ) variants for our app. Also in our app we use Dynamic Runtime Library (by default, FreeImage set up for static for some reason) How we usually got it:

    • Download and unpack fresh version (or at least clean up old distib)

    • Open FreeImage.2008.sln select ALL of 10 projects with Shift+click. Then in "Project(s) Properties / C++ / Code generation" we choose /MDd for "Debug" configuration and /MD for "Release".

    • Then we go to "Menu / Build / Batch build", select:

      FreeImageLib | Debug | Win32

      FreeImageLib | Release | Win32

    and press "Build".

    • Wait for choosen configurations built. All what we need will be copied in FreeImage\Dist folder

    • in FreeImage\Dist folder check files: delete.me FreeImage.h FreeImage.lib FreeImaged.lib Check creation date and time. It must be fresh baked and hot. If they not, copy them from FreeImage\Source\FreeImageLib\Debug and FreeImage\Source\FreeImageLib\Release.

    • In main applicaion add to include and lib FreeImage\Dist and link FreeImaged.lib to Debug configurations and FreeImage.lib to Releases.
    • Include in source file:

      #define FREEIMAGE_LIB

      #include "FreeImage.h"

    • Try to call FreeImage_Initialise(); FreeImage_DeInitialise();

    • It should work

    Happy coding!

    这篇关于将FreeImage链接为VS2010中的静态库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆