How to use FreeImage as static library in VC 2010?

Started by
7 comments, last by EnigmaticProgrammer 11 years, 11 months ago
The FreeImage source download has VC 2008 project files included. I convert them to VC 2010 and then build the FreeImageLib project. It builds fine but when I try to link to it I get the following errors:




2>msvcprt.lib(MSVCP100.dll) : error LNK2005: "public: void __thiscall std::_Container_base0::_Orphan_all(void)" (?_Orphan_all@_Container_base0@std@@QAEXXZ) already defined in FreeImage.lib(PluginGIF.obj)
2>msvcprt.lib(MSVCP100.dll) : error LNK2005: "public: class std::locale::facet * __thiscall std::locale::facet::_Decref(void)" (?_Decref@facet@locale@std@@QAEPAV123@XZ) already defined in FreeImage.lib(PluginEXR.obj)
2>libcpmt.lib(locale0.obj) : error LNK2005: "private: static void __cdecl std::locale::facet::_Facet_Register(class std::locale::facet *)" (?_Facet_Register@facet@locale@std@@CAXPAV123@@Z) already defined in msvcprt.lib(locale0_implib.obj)
2>libcpmt.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Getgloballocale(void)" (?_Getgloballocale@locale@std@@CAPAV_Locimp@12@XZ) already defined in msvcprt.lib(MSVCP100.dll)
2>libcpmt.lib(locale0.obj) : error LNK2005: "public: static void __cdecl std::_Locinfo::_Locinfo_dtor(class std::_Locinfo *)" (?_Locinfo_dtor@_Locinfo@std@@SAXPAV12@@Z) already defined in msvcprt.lib(MSVCP100.dll)
2>libcpmt.lib(locale0.obj) : error LNK2005: "public: static void __cdecl std::_Locinfo::_Locinfo_ctor(class std::_Locinfo *,char const *)" (?_Locinfo_ctor@_Locinfo@std@@SAXPAV12@PBD@Z) already defined in msvcprt.lib(MSVCP100.dll)
2>libcpmt.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Init(void)" (?_Init@locale@std@@CAPAV_Locimp@12@XZ) already defined in msvcprt.lib(MSVCP100.dll)
2>libcpmt.lib(ios.obj) : error LNK2005: "public: static void __cdecl std::ios_base::_Addstd(class std::ios_base *)" (?_Addstd@ios_base@std@@SAXPAV12@@Z) already defined in msvcprt.lib(MSVCP100.dll)
2>libcpmt.lib(ios.obj) : error LNK2005: "private: static void __cdecl std::ios_base::_Ios_base_dtor(class std::ios_base *)" (?_Ios_base_dtor@ios_base@std@@CAXPAV12@@Z) already defined in msvcprt.lib(MSVCP100.dll)
2>libcpmt.lib(xlock.obj) : error LNK2005: "public: __thiscall std::_Lockit::_Lockit(int)" (??0_Lockit@std@@QAE@H@Z) already defined in msvcprt.lib(MSVCP100.dll)
2>libcpmt.lib(xlock.obj) : error LNK2005: "public: __thiscall std::_Lockit::~_Lockit(void)" (??1_Lockit@std@@QAE@XZ) already defined in msvcprt.lib(MSVCP100.dll)
2>LIBCMT.lib(tidtable.obj) : error LNK2005: __encoded_null already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(tolower.obj) : error LNK2005: _tolower already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(dosmap.obj) : error LNK2005: __errno already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(lseeki64.obj) : error LNK2005: __lseeki64 already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(crt0dat.obj) : error LNK2005: __initterm_e already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(crt0dat.obj) : error LNK2005: _exit already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(crt0dat.obj) : error LNK2005: __amsg_exit already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(lconv.obj) : error LNK2005: _localeconv already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(crtheap.obj) : error LNK2005: __malloc_crt already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(mlock.obj) : error LNK2005: __unlock already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(mlock.obj) : error LNK2005: __lock already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(winxfltr.obj) : error LNK2005: ___CppXcptFilter already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(hooks.obj) : error LNK2005: "void __cdecl terminate(void)" (?terminate@@YAXXZ) already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in MSVCRT.lib(cinitexe.obj)
2>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in MSVCRT.lib(cinitexe.obj)
2>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in MSVCRT.lib(cinitexe.obj)
2>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in MSVCRT.lib(cinitexe.obj)
2>LIBCMT.lib(atox.obj) : error LNK2005: _atoi already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(strtol.obj) : error LNK2005: _strtol already defined in MSVCRT.lib(MSVCR100.dll)
2> libogg_static.lib(framing.obj) : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance
2>msvcprt.lib(MSVCP100.dll) : error LNK2005: "public: void __thiscall std::_Container_base0::_Orphan_all(void)" (?_Orphan_all@_Container_base0@std@@QAEXXZ) already defined in FreeImage.lib(PluginGIF.obj)
2>msvcprt.lib(MSVCP100.dll) : error LNK2005: "public: class std::locale::facet * __thiscall std::locale::facet::_Decref(void)" (?_Decref@facet@locale@std@@QAEPAV123@XZ) already defined in FreeImage.lib(PluginEXR.obj)
2>libcpmt.lib(locale0.obj) : error LNK2005: "private: static void __cdecl std::locale::facet::_Facet_Register(class std::locale::facet *)" (?_Facet_Register@facet@locale@std@@CAXPAV123@@Z) already defined in msvcprt.lib(locale0_implib.obj)
2>libcpmt.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Getgloballocale(void)" (?_Getgloballocale@locale@std@@CAPAV_Locimp@12@XZ) already defined in msvcprt.lib(MSVCP100.dll)
2>libcpmt.lib(locale0.obj) : error LNK2005: "public: static void __cdecl std::_Locinfo::_Locinfo_dtor(class std::_Locinfo *)" (?_Locinfo_dtor@_Locinfo@std@@SAXPAV12@@Z) already defined in msvcprt.lib(MSVCP100.dll)
2>libcpmt.lib(locale0.obj) : error LNK2005: "public: static void __cdecl std::_Locinfo::_Locinfo_ctor(class std::_Locinfo *,char const *)" (?_Locinfo_ctor@_Locinfo@std@@SAXPAV12@PBD@Z) already defined in msvcprt.lib(MSVCP100.dll)
2>libcpmt.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Init(void)" (?_Init@locale@std@@CAPAV_Locimp@12@XZ) already defined in msvcprt.lib(MSVCP100.dll)
2>libcpmt.lib(ios.obj) : error LNK2005: "public: static void __cdecl std::ios_base::_Addstd(class std::ios_base *)" (?_Addstd@ios_base@std@@SAXPAV12@@Z) already defined in msvcprt.lib(MSVCP100.dll)
2>libcpmt.lib(ios.obj) : error LNK2005: "private: static void __cdecl std::ios_base::_Ios_base_dtor(class std::ios_base *)" (?_Ios_base_dtor@ios_base@std@@CAXPAV12@@Z) already defined in msvcprt.lib(MSVCP100.dll)
2>libcpmt.lib(xlock.obj) : error LNK2005: "public: __thiscall std::_Lockit::_Lockit(int)" (??0_Lockit@std@@QAE@H@Z) already defined in msvcprt.lib(MSVCP100.dll)
2>libcpmt.lib(xlock.obj) : error LNK2005: "public: __thiscall std::_Lockit::~_Lockit(void)" (??1_Lockit@std@@QAE@XZ) already defined in msvcprt.lib(MSVCP100.dll)
2>LIBCMT.lib(tidtable.obj) : error LNK2005: __encoded_null already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(tolower.obj) : error LNK2005: _tolower already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(dosmap.obj) : error LNK2005: __errno already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(lseeki64.obj) : error LNK2005: __lseeki64 already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(crt0dat.obj) : error LNK2005: __initterm_e already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(crt0dat.obj) : error LNK2005: _exit already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(crt0dat.obj) : error LNK2005: __amsg_exit already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(lconv.obj) : error LNK2005: _localeconv already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(crtheap.obj) : error LNK2005: __malloc_crt already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(mlock.obj) : error LNK2005: __unlock already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(mlock.obj) : error LNK2005: __lock already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(winxfltr.obj) : error LNK2005: ___CppXcptFilter already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(hooks.obj) : error LNK2005: "void __cdecl terminate(void)" (?terminate@@YAXXZ) already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in MSVCRT.lib(cinitexe.obj)
2>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in MSVCRT.lib(cinitexe.obj)
2>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in MSVCRT.lib(cinitexe.obj)
2>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in MSVCRT.lib(cinitexe.obj)
2>LIBCMT.lib(atox.obj) : error LNK2005: _atoi already defined in MSVCRT.lib(MSVCR100.dll)
2>LIBCMT.lib(strtol.obj) : error LNK2005: _strtol already defined in MSVCRT.lib(MSVCR100.dll)
2> Creating library
2>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
2>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
2>LIBCMT.lib(crt0.obj) : error LNK2001: unresolved external symbol _main



From this post on stack overflow I would assume the problem is with using the VC 2008 project files but I don't know why? Any ideas what I'm doing wrong?
Advertisement
I ran into that as well, but can't remember the details. Are you mixing CRT versions? I think this came up when I rebuilt FreeImage but didn't rebuild all its dependencies.

I ran into that as well, but can't remember the details. Are you mixing CRT versions? I think this came up when I rebuilt FreeImage but didn't rebuild all its dependencies.


Yes, it is the CTR. I knew the CTR was the problem many months ago but I had forgotten. Now the problem is that I can change the CTR to match my program (Multi-threaded DLL (/MD)) but then the compiler builds a separate DLL which means it's no longer a static library. I know I can't mix CRT types but I'm linking to several other static libraries without a problem. Confused?huh.png
"[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]Multi-threaded DLL" doesn't mean that it will build DLL file. It will still build exelib or whatever you are building. Only difference from "[/background]

[/font][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]Multi-threaded" will be that your program will use CRT from DLL file and static CRT linked in your exe.[/background]

[/font]


"

[background=rgb(250, 251, 252)]Multi-threaded DLL" doesn't mean that it will build DLL file. It will still build exelib or whatever you are building. Only difference from "[/background]


[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]Multi-threaded" will be that your program will use CRT from DLL file and static CRT linked in your exe.[/background][/font]





Yeah, I just realized I was accidentally building the entire solution. Anyway, the CRT was not the problem. I'm still getting those errors... I believe I had already compiled it with the right CRT a few months ago when I did it.
Surely someone must understand what is wrong? I've tried everything but I'm still getting the same debug output.
These errors are typical of mixing two different runtimes as noted above. I do not have any other explanation for the symptoms in the original post. Something you are linking together was compiled using a different runtime than the rest of the code. Note that although you cannot mix the /MT and /MD runtimes, you cannot mix neither /MTd with /MT nor /MDd with /MD.

Edit: Also, since you mentioned compiling it a few months back, it is possible for (possibly automatic) updates to modify the version of the runtime. If that happens, even a previously /MD compiled library could possibly show the same symptoms when linking it with a current /MD program (the same goes for /MT, /MTd and /MDd). I did not keep track of the MSVC 2010 update schedule but I faintly remember something like this happening in MSVC 2008 at one point.

These errors are typical of mixing two different runtimes as noted above. I do not have any other explanation for the symptoms in the original post. Something you are linking together was compiled using a different runtime than the rest of the code. Note that although you cannot mix the /MT and /MD runtimes, you cannot mix neither /MTd with /MT nor /MDd with /MD.

Edit: Also, since you mentioned compiling it a few months back, it is possible for (possibly automatic) updates to modify the version of the runtime. If that happens, even a previously /MD compiled library could possibly show the same symptoms when linking it with a current /MD program (the same goes for /MT, /MTd and /MDd). I did not keep track of the MSVC 2010 update schedule but I faintly remember something like this happening in MSVC 2008 at one point.


Thanks to your response I realized it must be the other projects in the solution. I thought when I right clicked on a project and clicked build it was only building that project. However, it turns out that there was another sub menu which only builds that project but when I do that it says it needs the other projects. So I just had to set each project to Multi-threaded DLL and now it works perfectly! Thank you all for the help!
Actually problem is still not solved... Compiled prefect but all of the functions are returning null? blink.png

EDIT: Just needed to initialize it. rolleyes.gif

This topic is closed to new replies.

Advertisement