static linking issues

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

RickP
Not too shy to talk
Not too shy to talk
Posts: 37
Joined: Sat Mar 13, 2010 03:52

static linking issues

Postby RickP » Sun Mar 21, 2010 00:50

I did a search and found some stuff but couldn't figure out what is happening.

First off I got CEGUI working with the engine I'm using via the dll's. All that worked great. So now I'm trying to statically link to remove all those nasty dll's. I do have CEGUI_STATIC defined as well:

Code: Select all

#define CEGUI_STATIC

#include "CEGUI.h"
#include "CEGUIOpenGLRenderer.h"
#include "CEGUIDefaultResourceProvider.h"


Here are the files I'm linking to on the Release build:

Code: Select all

C:\CEGUI-SDK-0.7.1-vc9\lib\CEGUIBase_Static.lib
C:\CEGUI-SDK-0.7.1-vc9\lib\CEGUIOpenGLRenderer_Static.lib
C:\CEGUI-SDK-0.7.1-vc9\lib\CEGUIXercesParser_Static.lib
C:\CEGUI-SDK-0.7.1-vc9\lib\CEGUIExpatParser_Static.lib
C:\CEGUI-SDK-0.7.1-vc9\lib\CEGUIFalagardWRBase_Static.lib
C:\CEGUI-SDK-0.7.1-vc9\lib\CEGUISILLYImageCodec_Static.lib
C:\CEGUI-SDK-0.7.1-vc9\dependencies\lib\static\SILLY.lib
C:\CEGUI-SDK-0.7.1-vc9\dependencies\lib\static\xerces-c_static_3.lib
Opengl32.lib


So I basically took the dll names that I was using and linked the _Static and \static\ libraries. So with the non static libraries of the above and having the dll's it worked. Changing to the static libraries and removing the dll's I'm getting the following linker errors.


Code: Select all

1>------ Build started: Project: CEGUITest, Configuration: Release Win32 ------
1>Linking...
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "protected: char const * __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Myptr(void)const " (?_Myptr@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@IBEPBDXZ) already defined in CEGUIBase_Static.lib(CEGUIString.obj)
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: char const * __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::c_str(void)const " (?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ) already defined in CEGUIBase_Static.lib(CEGUIString.obj)
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in CEGUIBase_Static.lib(CEGUIString.obj)
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z) already defined in CEGUIBase_Static.lib(CEGUIString.obj)
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z) already defined in CEGUIBase_Static.lib(CEGUIString.obj)
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: class std::locale::facet * __thiscall std::locale::facet::_Decref(void)" (?_Decref@facet@locale@std@@QAEPAV123@XZ) already defined in CEGUIBase_Static.lib(CEGUIWindowManager.obj)
1>libcpmt.lib(locale0.obj) : error LNK2005: "void __cdecl _AtModuleExit(void (__cdecl*)(void))" (?_AtModuleExit@@YAXP6AXXZ@Z) already defined in msvcprt.lib(locale0_implib.obj)
1>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(MSVCP90.dll)
1>libcpmt.lib(locale0.obj) : error LNK2005: __Fac_tidy already defined in msvcprt.lib(locale0_implib.obj)
1>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)
1>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(MSVCP90.dll)
1>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(MSVCP90.dll)
1>libcpmt.lib(locale0.obj) : error LNK2005: "public: static void __cdecl std::_Locinfo::_Locinfo_ctor(class std::_Locinfo *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?_Locinfo_ctor@_Locinfo@std@@SAXPAV12@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z) already defined in msvcprt.lib(MSVCP90.dll)
1>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(MSVCP90.dll)
1>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(MSVCP90.dll)
1>libcpmt.lib(xlock.obj) : error LNK2005: "public: __thiscall std::_Lockit::_Lockit(int)" (??0_Lockit@std@@QAE@H@Z) already defined in msvcprt.lib(MSVCP90.dll)
1>libcpmt.lib(xlock.obj) : error LNK2005: "public: __thiscall std::_Lockit::~_Lockit(void)" (??1_Lockit@std@@QAE@XZ) already defined in msvcprt.lib(MSVCP90.dll)
1>LIBCMT.lib(setlocal.obj) : error LNK2005: __configthreadlocale already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(setlocal.obj) : error LNK2005: _setlocale already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(tidtable.obj) : error LNK2005: __encode_pointer already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(tidtable.obj) : error LNK2005: __decode_pointer already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(invarg.obj) : error LNK2005: __invalid_parameter_noinfo already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __amsg_exit already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __initterm_e already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: _exit already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __exit already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __cexit already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(lconv.obj) : error LNK2005: _localeconv already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(mlock.obj) : error LNK2005: __unlock already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(mlock.obj) : error LNK2005: __lock already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in MSVCRT.lib(cinitexe.obj)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in MSVCRT.lib(cinitexe.obj)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in MSVCRT.lib(cinitexe.obj)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in MSVCRT.lib(cinitexe.obj)
1>LIBCMT.lib(hooks.obj) : error LNK2005: "void __cdecl terminate(void)" (?terminate@@YAXXZ) already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(atox.obj) : error LNK2005: _atoi already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(dosmap.obj) : error LNK2005: __errno already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(crt0.obj) : error LNK2005: _mainCRTStartup already defined in MSVCRT.lib(crtexe.obj)
1>LIBCMT.lib(errmode.obj) : error LNK2005: ___set_app_type already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(_ctype.obj) : error LNK2005: _isspace already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(strtol.obj) : error LNK2005: _strtol already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(strtol.obj) : error LNK2005: _strtoul already defined in MSVCRT.lib(MSVCR90.dll)
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>CEGUIBase_Static.lib(CEGUISystem.obj) : error LNK2001: unresolved external symbol __imp__timeGetTime@0
1>CEGUIBase_Static.lib(CEGUIFreeTypeFont.obj) : error LNK2001: unresolved external symbol _FT_Load_Char
1>CEGUIBase_Static.lib(CEGUIFreeTypeFont.obj) : error LNK2001: unresolved external symbol _FT_Done_Face
1>CEGUIBase_Static.lib(CEGUIFreeTypeFont.obj) : error LNK2001: unresolved external symbol _FT_Get_Next_Char
1>CEGUIBase_Static.lib(CEGUIFreeTypeFont.obj) : error LNK2001: unresolved external symbol _FT_Get_First_Char
1>CEGUIBase_Static.lib(CEGUIFreeTypeFont.obj) : error LNK2001: unresolved external symbol _FT_Set_Char_Size
1>CEGUIBase_Static.lib(CEGUIFreeTypeFont.obj) : error LNK2001: unresolved external symbol _FT_New_Memory_Face
1>CEGUIBase_Static.lib(CEGUIFreeTypeFont.obj) : error LNK2001: unresolved external symbol _FT_Init_FreeType
1>CEGUIBase_Static.lib(CEGUIFreeTypeFont.obj) : error LNK2001: unresolved external symbol _FT_Done_FreeType
1>CEGUIBase_Static.lib(CEGUIPCRERegexMatcher.obj) : error LNK2001: unresolved external symbol _pcre_free
1>CEGUIBase_Static.lib(CEGUIPCRERegexMatcher.obj) : error LNK2001: unresolved external symbol _pcre_exec
1>CEGUIBase_Static.lib(CEGUIPCRERegexMatcher.obj) : error LNK2001: unresolved external symbol _pcre_compile
1>CEGUIOpenGLRenderer_Static.lib(CEGUIOpenGLRenderTarget.obj) : error LNK2001: unresolved external symbol _gluProject@48
1>CEGUIOpenGLRenderer_Static.lib(CEGUIOpenGLRenderTarget.obj) : error LNK2001: unresolved external symbol _gluUnProject@48
1>CEGUIOpenGLRenderer_Static.lib(CEGUIOpenGLRenderTarget.obj) : error LNK2001: unresolved external symbol _gluLookAt@72
1>CEGUIOpenGLRenderer_Static.lib(CEGUIOpenGLRenderTarget.obj) : error LNK2001: unresolved external symbol _gluPerspective@32
1>SILLY.lib(SILLYPNGImageLoader.obj) : error LNK2001: unresolved external symbol _png_error
1>SILLY.lib(SILLYPNGImageLoader.obj) : error LNK2001: unresolved external symbol _png_get_io_ptr
1>SILLY.lib(SILLYPNGImageLoader.obj) : error LNK2001: unresolved external symbol _png_get_channels
1>SILLY.lib(SILLYPNGImageLoader.obj) : error LNK2001: unresolved external symbol _png_get_bit_depth
1>SILLY.lib(SILLYPNGImageLoader.obj) : error LNK2001: unresolved external symbol _png_read_png
1>SILLY.lib(SILLYPNGImageLoader.obj) : error LNK2001: unresolved external symbol _png_set_read_fn
1>SILLY.lib(SILLYPNGImageLoader.obj) : error LNK2001: unresolved external symbol _png_set_error_fn
1>SILLY.lib(SILLYPNGImageLoader.obj) : error LNK2001: unresolved external symbol _png_create_info_struct
1>SILLY.lib(SILLYPNGImageLoader.obj) : error LNK2001: unresolved external symbol _png_create_read_struct
1>SILLY.lib(SILLYPNGImageLoader.obj) : error LNK2001: unresolved external symbol _png_get_rows
1>SILLY.lib(SILLYJPGImageLoader.obj) : error LNK2001: unresolved external symbol _jpeg_finish_decompress
1>SILLY.lib(SILLYJPGImageLoader.obj) : error LNK2001: unresolved external symbol _jpeg_start_decompress
1>SILLY.lib(SILLYJPGImageLoader.obj) : error LNK2001: unresolved external symbol _jpeg_read_header
1>SILLY.lib(SILLYJPGImageLoader.obj) : error LNK2001: unresolved external symbol _jpeg_read_scanlines
1>SILLY.lib(SILLYPNGImageContext.obj) : error LNK2001: unresolved external symbol _png_destroy_read_struct
1>SILLY.lib(SILLYPNGImageContext.obj) : error LNK2001: unresolved external symbol _png_get_image_height
1>SILLY.lib(SILLYPNGImageContext.obj) : error LNK2001: unresolved external symbol _png_get_image_width
1>SILLY.lib(SILLYJPGImageContext.obj) : error LNK2001: unresolved external symbol _jpeg_std_error
1>SILLY.lib(SILLYJPGImageContext.obj) : error LNK2001: unresolved external symbol _jpeg_CreateDecompress
1>SILLY.lib(SILLYJPGImageContext.obj) : error LNK2001: unresolved external symbol _jpeg_resync_to_restart
1>SILLY.lib(SILLYJPGImageContext.obj) : error LNK2001: unresolved external symbol _jpeg_destroy_decompress
1>.\CEGUITest-Release.exe : fatal error LNK1120: 37 unresolved externals
1>Build log was saved at "file://c:\CEGUITest\Release\BuildLog.htm"
1>CEGUITest - 82 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========\

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: static linking issues

Postby CrazyEddie » Sun Mar 21, 2010 07:18

As mentioned in the other thread, this will be because the static dependencies are built with the /MT and /MTd runtime options, though the CEGUI dll and such will be using the /MD and /MDd options. You might end up having to recompile the dependencies - unless you are only needing a specific subset. Meaning if you just want rid of the SILLY dlls and such, you would just need a customised build of SILLY and a tweak to the SILLYImageCodec project - the other 'required' deps such as freetype and pcre are already static for DLL builds, as it the expat parser.

Also, when statically linking CEGUI you need only specify one XML parser lib ;)

CE.

RickP
Not too shy to talk
Not too shy to talk
Posts: 37
Joined: Sat Mar 13, 2010 03:52

Re: static linking issues

Postby RickP » Sun Mar 21, 2010 17:59

Is there a VS setup for SILLY? I see this has some dependencies of some jpeg/png lib? This rabit hole is deep :)

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: static linking issues

Postby CrazyEddie » Mon Mar 22, 2010 07:06

SILLY uses premake for MSVC++ solution creation, so just run the premake.exe (you can use the one from CEGUI) in the root SILLY directory - as an aside, does the source package not contain the solution?

For the dependencies, you can either grab a copy of the SILLY dependencies from the same download page (or use this link: http://prdownloads.sourceforge.net/cray ... p?download) - note that these versions are a bit old now, but don't use the ones in the CEGUI dependencies, as they're linked with /MT and /MTd.

CE.

RickP
Not too shy to talk
Not too shy to talk
Posts: 37
Joined: Sat Mar 13, 2010 03:52

Re: static linking issues

Postby RickP » Mon Mar 22, 2010 11:42

SILLY uses premake for MSVC++ solution creation, so just run the premake.exe (you can use the one from CEGUI) in the root SILLY directory - as an aside, does the source package not contain the solution?


hmm, I did run the premake that was in the SILLY dir but it didn't work. It just closes really fast and I can't seem to see any errors. I also did not see any MSVC++ solution with SILLY either.

RickP
Not too shy to talk
Not too shy to talk
Posts: 37
Joined: Sat Mar 13, 2010 03:52

Re: static linking issues

Postby RickP » Mon Mar 22, 2010 15:02

So since premake wasn't working for me I just created an empty static library project. I added all the .cpp files and added the .h directory. I then added the jpeg, png, & zlib libraries. I have 1 error and not sure what to do about it.

Code: Select all

Error   42   error C2491: 'SILLY::ImageLoaderManager::d_instance' : definition of dllimport static data member not allowed   c:\silly-0.1.0\silly\silly\sillyimageloadermanager.cpp   60   SILLY


Any ideas?

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

Re: static linking issues

Postby Jamarr » Mon Mar 22, 2010 18:03

In regards to the msvc runtimes you need to decide if you want to distribute the msvc runtimes along with your software (/MD) or if you want to also statically link the msvc runtimes (/MT). Basically, each project needs to be compiled with the same msvc runtime configuration. The new precompiled static dependencies all use /MT (afaik); where as the new precompiled dll dependencies all use /MD (afaik).

In regards to SILLY, I suggest you figure out how to open a command shell/prompt (eg start->run->cmd.exe) from which you can run premake and see it's output without having it "close really fast." Premake will create a project for you with the necessary dependencies and precompiler necessary for compiling. Of course if you change your projects msvc runtime configuration to /MT and link to the new precompiled static libraries, you can avoid having to build all of the dependencies from source...in theory (I haven't actually tested the new packages myself).
If somebody helps you by replying to your thread, upvote him/her as a thanks! Make sure to include your CEGUI.log and everything you tried when posting! And remember that we are not magicians!

RickP
Not too shy to talk
Not too shy to talk
Posts: 37
Joined: Sat Mar 13, 2010 03:52

Re: static linking issues

Postby RickP » Mon Mar 22, 2010 18:19

Of course if you change your projects msvc runtime configuration to /MT and link to the new precompiled static libraries, you can avoid having to build all of the dependencies from source...in theory (I haven't actually tested the new packages myself).


I guess I thought that's what I was doing. hmm

RickP
Not too shy to talk
Not too shy to talk
Posts: 37
Joined: Sat Mar 13, 2010 03:52

Re: static linking issues

Postby RickP » Mon Mar 22, 2010 18:36

Oh I see. If I change my project to /MT then all msvcprt.lib errors go away and all that is left are:

Code: Select all

1>CEGUIBase_Static.lib(CEGUISystem.obj) : error LNK2001: unresolved external symbol __imp__timeGetTime@0
1>CEGUIBase_Static.lib(CEGUIFreeTypeFont.obj) : error LNK2001: unresolved external symbol _FT_Load_Char
1>CEGUIBase_Static.lib(CEGUIFreeTypeFont.obj) : error LNK2001: unresolved external symbol _FT_Done_Face
1>CEGUIBase_Static.lib(CEGUIFreeTypeFont.obj) : error LNK2001: unresolved external symbol _FT_Get_Next_Char
1>CEGUIBase_Static.lib(CEGUIFreeTypeFont.obj) : error LNK2001: unresolved external symbol _FT_Get_First_Char
1>CEGUIBase_Static.lib(CEGUIFreeTypeFont.obj) : error LNK2001: unresolved external symbol _FT_Set_Char_Size
1>CEGUIBase_Static.lib(CEGUIFreeTypeFont.obj) : error LNK2001: unresolved external symbol _FT_New_Memory_Face
1>CEGUIBase_Static.lib(CEGUIFreeTypeFont.obj) : error LNK2001: unresolved external symbol _FT_Init_FreeType
1>CEGUIBase_Static.lib(CEGUIFreeTypeFont.obj) : error LNK2001: unresolved external symbol _FT_Done_FreeType
1>CEGUIOpenGLRenderer_Static.lib(CEGUIOpenGLRenderTarget.obj) : error LNK2001: unresolved external symbol _gluProject@48
1>CEGUIOpenGLRenderer_Static.lib(CEGUIOpenGLRenderTarget.obj) : error LNK2001: unresolved external symbol _gluUnProject@48
1>CEGUIOpenGLRenderer_Static.lib(CEGUIOpenGLRenderTarget.obj) : error LNK2001: unresolved external symbol _gluLookAt@72
1>CEGUIOpenGLRenderer_Static.lib(CEGUIOpenGLRenderTarget.obj) : error LNK2001: unresolved external symbol _gluPerspective@32
1>SILLY.lib(SILLYPNGImageLoader.obj) : error LNK2001: unresolved external symbol _png_error
1>SILLY.lib(SILLYPNGImageLoader.obj) : error LNK2001: unresolved external symbol _png_get_io_ptr
1>SILLY.lib(SILLYPNGImageLoader.obj) : error LNK2001: unresolved external symbol _png_get_channels
1>SILLY.lib(SILLYPNGImageLoader.obj) : error LNK2001: unresolved external symbol _png_get_bit_depth
1>SILLY.lib(SILLYPNGImageLoader.obj) : error LNK2001: unresolved external symbol _png_read_png
1>SILLY.lib(SILLYPNGImageLoader.obj) : error LNK2001: unresolved external symbol _png_set_read_fn
1>SILLY.lib(SILLYPNGImageLoader.obj) : error LNK2001: unresolved external symbol _png_set_error_fn
1>SILLY.lib(SILLYPNGImageLoader.obj) : error LNK2001: unresolved external symbol _png_create_info_struct
1>SILLY.lib(SILLYPNGImageLoader.obj) : error LNK2001: unresolved external symbol _png_create_read_struct
1>SILLY.lib(SILLYPNGImageLoader.obj) : error LNK2001: unresolved external symbol _png_get_rows
1>SILLY.lib(SILLYJPGImageLoader.obj) : error LNK2001: unresolved external symbol _jpeg_finish_decompress
1>SILLY.lib(SILLYJPGImageLoader.obj) : error LNK2001: unresolved external symbol _jpeg_start_decompress
1>SILLY.lib(SILLYJPGImageLoader.obj) : error LNK2001: unresolved external symbol _jpeg_read_header
1>SILLY.lib(SILLYJPGImageLoader.obj) : error LNK2001: unresolved external symbol _jpeg_read_scanlines
1>SILLY.lib(SILLYPNGImageContext.obj) : error LNK2001: unresolved external symbol _png_destroy_read_struct
1>SILLY.lib(SILLYPNGImageContext.obj) : error LNK2001: unresolved external symbol _png_get_image_height
1>SILLY.lib(SILLYPNGImageContext.obj) : error LNK2001: unresolved external symbol _png_get_image_width
1>SILLY.lib(SILLYJPGImageContext.obj) : error LNK2001: unresolved external symbol _jpeg_std_error
1>SILLY.lib(SILLYJPGImageContext.obj) : error LNK2001: unresolved external symbol _jpeg_CreateDecompress
1>SILLY.lib(SILLYJPGImageContext.obj) : error LNK2001: unresolved external symbol _jpeg_resync_to_restart
1>SILLY.lib(SILLYJPGImageContext.obj) : error LNK2001: unresolved external symbol _jpeg_destroy_decompress


So I'm guessing I would need to recompile those static libs with /MT as well? When I download the source it looks like these are already setup as /MT. So why would I still get unresolved external symbol errors?

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: static linking issues

Postby CrazyEddie » Tue Mar 23, 2010 11:32

No, no, these are just missing libs ;) All you have to do is ensure you link the ones from the static directory in the deps (where applicable).

timeGetTime is a Win32 function and is in winmm.lib

the FT_ ones are freetype: freetype.lib (freetype_D.lib in debug)
the glu ones are from the GL utility lib: glu32.lib
the png and jpg ones need: libpng, jpeg and zlib (libpng_d jpeg_d and zlib_d in debug).

CE.

RickP
Not too shy to talk
Not too shy to talk
Posts: 37
Joined: Sat Mar 13, 2010 03:52

Re: static linking issues

Postby RickP » Wed Mar 24, 2010 00:28

Cool, I got this working in an exe. So my next steps will be to make my own dll and statically link all these dependencies into it, and then all the users of this engine should need is the includes, my lib, and the dll and it should be good to go! They will be excited for sure. Thanks for your help on this guys.

Rick

RickP
Not too shy to talk
Not too shy to talk
Posts: 37
Joined: Sat Mar 13, 2010 03:52

Re: static linking issues

Postby RickP » Wed Mar 24, 2010 01:54

So maybe I'm thinking about this the wrong way. I don't have much experience with making dlls/libraries in C++.

My plan was to compile statically CEGUI into my own custom dll. So I created this custom dll project, and statically linked the parts of CEGUI I need. That worked all fine. I got a dll and a lib file from that. Now it's my understanding that because I statically linked the cegui libraries that my dll now has all that library code inside of it. Meaning that if I was to use this new dll I made I wouldn't have to add any other libraries to a new exe project but this new dll .lib file that comes with it and this would work? I assumed it would still require the header files, but the .lib files of cegui should all be compiled in my dll right?

When I do this and just create my class object that I created in my dll I get:
1>CEGUITest.obj : error LNK2001: unresolved external symbol "public: __thiscall LECEGUI::~LECEGUI(void)" (??1LECEGUI@@QAE@XZ)
1>CEGUITest.obj : error LNK2001: unresolved external symbol "public: __thiscall LECEGUI::LECEGUI(void)" (??0LECEGUI@@QAE@XZ)

Which tells me that the .lib to my dll doesn't seem to be working.


Am I thinking right here or am I way off base on how this works?

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: static linking issues

Postby CrazyEddie » Wed Mar 24, 2010 10:40

For a DLL you need to apply code that controls whether symbols are imported or exported. Generally this is done using a preprocessor macro system. For example, a simplified version of how we do that in CEGUI is:

Code: Select all

#ifdef CEGUIBASE_EXPORTS
#    define CEGUIEXPORT __declspec(dllexport)
#else
#    define CEGUIEXPORT __declspec(dllimport)
#endif


You then use 'CEGUIEXPORT' with functions and classes to automatically import/export as appropriate according to whether you're building the DLL itself - in which case we define CEGUIBASE_EXPORTS - or building client code of the DLL, in which case you do not define CEGUIBASE_EXPORTS.

To import/export a function:

Code: Select all

CEGUIEXPORT void MyFunction();


To import/export a class:

Code: Select all

class CEGUIEXPORT MyClass
{
public:
    MyClass();
    ~MyClass();
    ...
};


Btw, don't use that construct above vertabim - change the macro names to something appropriate for your project - otherwise there will be conflicts as we use those in CEGUI ;)

HTH

CE.

RickP
Not too shy to talk
Not too shy to talk
Posts: 37
Joined: Sat Mar 13, 2010 03:52

Re: static linking issues

Postby RickP » Wed Mar 24, 2010 12:11

I actually did that, but now that I think about it, always best to sleep on an issue :), I didn't do that on the constructor/destructor functions. I'm guessing that's it! I didn't use a macro for the export/import I just typed it out :)

RickP
Not too shy to talk
Not too shy to talk
Posts: 37
Joined: Sat Mar 13, 2010 03:52

Re: static linking issues

Postby RickP » Wed Mar 24, 2010 14:52

OK, so that worked. I can now use my class and it's methods. But when I try to put CEGUI specific code into the exe program I get linker errors about the missing functions. My assumption is that since I statically linked the CEGUI stuff into my own DLL, that my DLL's lib file would have these in there also, but it's not looking like that. I assume the static libraries for CEGUI don't have the __declspec(dllexport) on them so they won't be in my dll's lib file right? Is there some macro or something that I can set so that the CEGUI stuff when compiled into my dll will also be available for usage in an exe project? I don't wish to encapsulate all of the CEGUI stuff, just some. For creating widgets and such I still wish for the user to use normal CEGUI classes.

So it's like I want CEGUI to be statically linked into my DLL but still exposed through my DLL.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 24 guests