Linker Error in Visual Studio 2008

Help
L. Spiro
2014-06-05
2014-06-14
  • L. Spiro

    L. Spiro - 2014-06-05

    I have added FreeImageLib.2008.vcproj to my project and set dependencies on it.
    Upon building it performs the 2 post-build operations which copy FreeImage.lib or FreeImaged.lib to the FreeImage\Dist directory.

    I link to the following in the release build of my project:
    "$(ProjectDir)Src\FreeImage\Dist\FreeImage.lib"
    …which resolves to the correct path (if I change FreeImage.lib to FreeImageadadadw.lib I get a file-not-found error).

    Finally, I added calls to FreeImage_Initialise() and FreeImage_DeInitialise() and get the following linker errors:
    2>LSImageLib.lib(LSIImageLib.obj) : error LNK2001: unresolved external symbol impFreeImage_DeInitialise@0
    2>LSImageLib.lib(LSIImageLib.obj) : error LNK2001: unresolved external symbol impFreeImage_Initialise@4

    I have also added FreeImage as a reference (Common Properties -> Framework and References).

    Any ideas will be appreciated.

    L. Spiro

     
    • L. Spiro

      L. Spiro - 2014-06-05

      Of note, I added the following macros to the LSImageLib project:
      OPJ_STATIC;FREEIMAGE_LIB;_CRT_SECURE_NO_DEPRECATE;LIBRAW_NODLL

      The linker error has now become:
      3>LSImageLib.lib(LSIImageLib.obj) : error LNK2001: unresolved external symbol _FreeImage_DeInitialise@0
      3>LSImageLib.lib(LSIImageLib.obj) : error LNK2001: unresolved external symbol _FreeImage_Initialise@4

      FreeImage.lib contains the text “_FreeImage_Initialise” twice, but no occurrences of “_FreeImage_Initialise@4”.
      It appears to be a decoration issue. Possibly a project setting somewhere I haven’t found?

      L. Spiro

       
  • L. Spiro

    L. Spiro - 2014-06-07

    By now you can tell I’ve not made beginners’ mistakes and indeed I have been programming for over 18 years, professionally for 11 years. I make the underlying technology behind Final Fantasy games.

    “_FreeImage_Initialise” is the name decoration for cdecl and “_FreeImage_Initialise@4” is the decoration for stdcall (when inside “extern "C"” blocks), so it’s obvious that the library compiles viewing FreeImage_Initialise as cdecl and my library (LSImageLib) views the same header file as declaring it to be stdcall (so it looks for that in the library and of course fails to find it).

    The solution should be obvious:
    DLL_API void DLL_CALLCONV FreeImage_Initialise(BOOL load_local_plugins_only FI_DEFAULT(FALSE));
    ->
    DLL_API void _cdecl FreeImage_Initialise(BOOL load_local_plugins_only FI_DEFAULT(FALSE));
    (as a test)
    Now everything must see it as __cdecl.

    Result:
    fatal error LNK1120: 243 unresolved externals
    3>Linking...
    3>lsimagelib.lib(LSIImageLib.obj) : error LNK2001: unresolved external symbol _FreeImage_DeInitialise@0
    3>FreeImage.lib(PluginTIFF.obj) : error LNK2001: unresolved external symbol _TIFFLastDirectory
    3>FreeImage.lib(PluginTIFF.obj) : error LNK2001: unresolved external symbol _TIFFReadEXIFDirectory
    3>FreeImage.lib(PluginTIFF.obj) : error LNK2001: unresolved external symbol _TIFFStripSize
    3>FreeImage.lib(PluginTIFF.obj) : error LNK2001: unresolved external symbol _TIFFClientOpen
    (…)

    Notice that I have fixed the linker error related to FreeImage_Initialise only to incur quite a wrath of miscellaneous linker errors elsewhere.

    The calling conventions between libraries are not enforced, and as such it is literally impossible to build a static library out of this.

    Temporarily I will build the DLL and use that, but please fix this issue.

    L. Spiro

     
  • Hervé Drolon

    Hervé Drolon - 2014-06-14

    Hi,

    see http://freeimage.sourceforge.net/faq.html

    FreeImage lib has been compiled and used as a static libray for more than 14 years now, without problem.

    Hervé

     

Log in to post a comment.