[SOLVED] Building Ogre 1.7 Project using Cegui 0.7.1 Linking

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

xekon
Just popping in
Just popping in
Posts: 14
Joined: Thu Jan 21, 2010 00:07

[SOLVED] Building Ogre 1.7 Project using Cegui 0.7.1 Linking

Postby xekon » Thu Jan 21, 2010 00:13

I am using Ogre 1.7 from SVN and Cegui 0.7.1 from SVN, I am using MSVC9 (Visual Studio 2008)

My project is going to start as a basic framework using Ogre 1.7 and Cegui 0.7.1, So far I have taken Xavier's Practical Application example: http://test.ogitor.org/tiki/Practical+A ... et+Started
and got it working with ogre 1.7, now I am going to try and incorporate Cegui 0.7.1 for some menu's and stuff, and then maybe add to his tutorial or release it or something, in hopes that it helps others trying to get started with the NEW Ogre 1.7 and NEW Cegui 0.7.1

I do not have a cegui log.. because it is a build/linking error, I've done a good amount of searching, and reading the tutorials and rules, im still newish to this, I've gone over it several times and cannot find what im missing.

I get an Unresolved external symbol error when I try to build (usually happens when something in the project settings isn't included, can't figure out what it could be)

Code: Select all

1>------ Build started: Project: frame, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>Linking...
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static class CEGUI::OgreRenderer & __cdecl CEGUI::OgreRenderer::create(void)" (__imp_?create@OgreRenderer@CEGUI@@SAAAV12@XZ)
1>C:\Program Files (x86)\ogre\build\bin\debug\frame.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://C:\Program Files (x86)\ogre\build\bin\debug\BuildLog.htm"
1>frame - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I compiled both from source.

In my ogre project's settings I have added the additional include directory: cegui\cegui\include

I copied "CEGUIBase_Static_d.lib" & "CEGUIOgreRenderer_Static_d" to my "ogre\Dependencies\lib\Debug" folder,
which is in my Project's "Additional Library Directories" settings

I have "CEGUIBase_Static_d.lib" & "CEGUIOgreRenderer_Static_d.lib" defined in my additional dependencies:

Code: Select all

OgreMain_d.lib
OIS_d.lib
dxguid.lib
dinput8.lib
CEGUIBase_Static_d.lib
CEGUIOgreRenderer_Static_d.lib

I copied all the .dll files from cegui\dependencies\bin to my working directory.

I copied everything from the "cegui\dependencies\include" folder into my "ogre\Dependencies\include" folder
"ogre\Dependencies\include" is set as an include directory in my project settings as well.

in my Ogre application where my includes are (in main.cpp) i have:

Code: Select all

// CEGUI includes
#include "CEGUI.h"
#include "RendererModules/Ogre/CEGUIOgreRenderer.h"

then I proceeded to add (without this line there are no building issues... but then the only cegui related stuff are the two includes.):

Code: Select all

   CEGUI::OgreRenderer& myRenderer = CEGUI::OgreRenderer::create();

to my WinMain{} section below:

Code: Select all

    Ogre::Root *ogre;
    Ogre::RenderWindow *window;
    Ogre::SceneManager *sceneMgr;
    Ogre::Camera *camera;

As outlined here: http://www.cegui.org.uk/docs/current/re ... orial.html
Last edited by xekon on Fri Jan 29, 2010 23:40, edited 1 time in total.

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

Re: Building Ogre 1.7 Project using Cegui 0.7.1 Linking error.

Postby CrazyEddie » Thu Jan 21, 2010 09:39

Hi,

When linking statically you have to define the preprocessor macro:

Code: Select all

CEGUI_STATIC

This should resolve that particular linker error.

You will also need to be aware that the static builds of Ogre (at least the one's I have tested, though I confess I have not tested the 1.7 versions) link against, and use dependencies that are linked against, the DLL based c/c++ runtime whereas CEGUI and it's static dependencies are linked against the static c/c++ runtime (as might be more commonly expected when linking statically). This mismatch will almost certainly cause conflicts of one type or another, usually manifesting as linker warnings and runtime heap corruption. The only way around this is to modify the configuration of one of the libs and rebuild.

CE

xekon
Just popping in
Just popping in
Posts: 14
Joined: Thu Jan 21, 2010 00:07

Re: Building Ogre 1.7 Project using Cegui 0.7.1 Linking error.

Postby xekon » Fri Jan 22, 2010 00:17

CrazyEddie wrote:The only way around this is to modify the configuration of one of the libs and rebuild.

CE


FIRST! Thank you so much for taking the time to help me, I know you and most other developers are generally pretty busy, and I appreciate the help greatly.

So I want both Ogre and its dependencies & Cegui and its dependencies... to be built the same way.

I just used Cmake for the first time when I built Ogre 1.7 SVN from source.

I also just used Premake for the first time when I built CEGUI SVN...

when you say to modify the configuration of one of the "libs" and rebuild, you are referring to both Ogre and Cegui correct?

*and by modify do you mean change it from a static library to a dynamic library? or do you mean link statically still but in a different way?

*are there specific options in the config.lua file for cegui premake settings. or do you mean I actually need to recompile Cegui's dependencies in a dll fashion like ogre does...

(sorry for the newbie questions, I appreciate the help and hopefully I can reciprocate by helping others once I have a better understanding.)

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

Re: Building Ogre 1.7 Project using Cegui 0.7.1 Linking error.

Postby CrazyEddie » Fri Jan 22, 2010 09:49

xekon wrote:FIRST! Thank you so much for taking the time to help me, I know you and most other developers are generally pretty busy, and I appreciate the help greatly.

No problem. We do, genuinely, try our best to help everybody as best as we can.

xekon wrote:when you say to modify the configuration of one of the "libs" and rebuild, you are referring to both Ogre and Cegui correct?

*and by modify do you mean change it from a static library to a dynamic library? or do you mean link statically still but in a different way?

Basically, it means that everything being linked together - whether statically or dynamically - needs to have the same c/c++ runtime configuration - which means your own app, the Ogre libraries, the Ogre dependencies, the CEGUI libraries and the CEGUI dependencies. There are numerous ways to go about achieving this, though obviously you want the most painless method while still achieving what you're aiming for. The absolute most painless way would be to switch from static to dynamic linking - because using this configuration, everything is set up already to use the 'correct' runtime. However, I assume you'd prefer to keep the static linking approach you've chosen; this leaves a couple of choices:
  • 1) Rebuild Ogre's static libs and it's dependency libs against the static c/c++ runtime.
    - or -
  • 2) Rebuild CEGUI's static libs against the dynamically linked dependencies that we provide for the CEGUI dynamic libs.
xekon wrote:or do you mean I actually need to recompile Cegui's dependencies in a dll fashion like ogre does...

There's no need to do this, because we already provide the dependencies compiled both ways. So, because we're already providing the dependency library in two separate configurations, clearly, option 2 is, I think, the way you'll want to go. However there is a small snag...

xekon wrote: *are there specific options in the config.lua file for cegui premake settings.

As things stand right at this moment, there is no configurable option that allows you to choose which set of dependencies you want to use for the static build; it's hard wired - the dynamic c/c++ runtime versions for dynamic linking of CEGUI and the static c/c++ runtime versions for static linking of CEGUI. I am willing, however, to add an option to the premake system that allows this to be a user configurable setting (so it will be possible to build static CEGUI libs that are linked against the dynamically linked dependencies). I will try to get this done today.

Also, one final thing I forgot in my initial reply - when linking statically you have to additionally explicity add the libs for the dependencies and runtime modules (meaning those that are usually loaded dynamically, but not linked to - xml parser module, window renderer module and so on). So you need some additional libs, such as:

Code: Select all

CEGUIFalagardWRBase_Static_d.lib
CEGUIExpatXMLParser_d.lib
CEGUISILLYImageCodec_d.lib (not usually used with Ogre, but maybe needed due to system default configurations)
pcre_d.lib
freetype_d.lib
expat_d.lib

This list may not be 100% complete, but I think you get the picture.

I'll advise once I've added the dependency version configuration option.

CE.

Edited to fix some quoting and what not...

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

Re: Building Ogre 1.7 Project using Cegui 0.7.1 Linking error.

Postby CrazyEddie » Fri Jan 22, 2010 12:31

Ok. If you update from SVN (v0-7 branch) you should now find an option in config.lua named 'STATIC_BUILD_WITH_DYNAMIC_DEPS' if you se this to true, it will use the DLL version of the c/c++ runtime and the appropriate version of our dependencies that also use the same c/c++ runtime setting.

HTH

CE.

xekon
Just popping in
Just popping in
Posts: 14
Joined: Thu Jan 21, 2010 00:07

Re: Building Ogre 1.7 Project using Cegui 0.7.1 Linking error.

Postby xekon » Sat Jan 23, 2010 19:43

CrazyEddie wrote:Ok. If you update from SVN (v0-7 branch) you should now find an option in config.lua named 'STATIC_BUILD_WITH_DYNAMIC_DEPS' if you se this to true, it will use the DLL version of the c/c++ runtime and the appropriate version of our dependencies that also use the same c/c++ runtime setting.

HTH

CE.


Very COOL, THANK YOU! I tried starting over this morning, with fresh svn: http://www.cegui.org.uk/wiki/index.php/ ... subversion

I use TortoiseSVN so I used this address: https://crayzedsgui.svn.sourceforge.net ... _mk2/trunk

I did not see "STATIC_BUILD_WITH_DYNAMIC_DEPS" in the cegui\projects\premake\config.lua file. I am wondering if I downloaded from SVN using the wrong address, or if the changes still need to be committed to the SVN is all.

mukik182
Just popping in
Just popping in
Posts: 4
Joined: Tue Dec 08, 2009 18:55
Location: Barcelona, Spain

Re: Building Ogre 1.7 Project using Cegui 0.7.1 Linking error.

Postby mukik182 » Sat Jan 23, 2010 19:55

You checked trunk and you should check v0-7 branch.

https://crayzedsgui.svn.sourceforge.net ... nches/v0-7

xekon
Just popping in
Just popping in
Posts: 14
Joined: Thu Jan 21, 2010 00:07

Re: Building Ogre 1.7 Project using Cegui 0.7.1 Linking error.

Postby xekon » Sun Jan 24, 2010 21:28

CrazyEddie wrote:Also, one final thing I forgot in my initial reply - when linking statically you have to additionally explicity add the libs for the dependencies and runtime modules (meaning those that are usually loaded dynamically, but not linked to - xml parser module, window renderer module and so on). So you need some additional libs, such as:

Code: Select all

CEGUIFalagardWRBase_Static_d.lib
CEGUIExpatXMLParser_d.lib
CEGUISILLYImageCodec_d.lib (not usually used with Ogre, but maybe needed due to system default configurations)
pcre_d.lib
freetype_d.lib
expat_d.lib

This list may not be 100% complete, but I think you get the picture.

I'll advise once I've added the dependency version configuration option.


CrazyEddi: SILLY_d was also needed, i got a bunch of unresolved external symbol errors, I guessed that it was silly_d because it referenced functions that started with "SILLY::Image::blahblahblah" So I was able to guess that one.

But how do you determine the library your missing when you get an error like the following (is there a way to do a search on each library to find the function its calling, in this case, CEGUI::SimpleTimer::currentTime(void))

Code: Select all

1>CEGUIBase_Static_d.lib(CEGUISystem.obj) : error LNK2019: unresolved external symbol __imp__timeGetTime@0 referenced in function "public: static double __cdecl CEGUI::SimpleTimer::currentTime(void)" (?currentTime@SimpleTimer@CEGUI@@SANXZ)


AGAIN! thank you for your help, I've already learned quite a bit!

Also Thanks muklik182, I did not see that link on the wiki and figured I probably just had the wrong address.

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

Re: Building Ogre 1.7 Project using Cegui 0.7.1 Linking error.

Postby CrazyEddie » Mon Jan 25, 2010 09:09

xekon wrote:But how do you determine the library your missing when you get an error like the following (is there a way to do a search on each library to find the function its calling, in this case, CEGUI::SimpleTimer::currentTime(void))

How do I determine the lib? Experience ;) How do others do it and is there a tool? I have no idea TBH, though one way is to identify the symbol name, use judgement as to where it relates to (as you did with the SILLY one!) and then, if possible, search...

xekon wrote:

Code: Select all

1>CEGUIBase_Static_d.lib(CEGUISystem.obj) : error LNK2019: unresolved external symbol __imp__timeGetTime@0 referenced in function "public: static double __cdecl CEGUI::SimpleTimer::currentTime(void)" (?currentTime@SimpleTimer@CEGUI@@SANXZ)

In this instance the missing symbol is __imp__timeGetTime@0, so that's timeGetTime which is a Win32 function, so searching MSDN yields: this page and reading this we can see the function is in the library: Winmm.lib - so that's the one you're missing.

Also, those libs I mentioned above such as CEGUIExpatXMLParser_d.lib and CEGUISILLYImageCodec_d.lib, I think they should have been CEGUIExpatXMLParser_Static_d.lib and CEGUISILLYImageCodec_Static_d.lib, though I guess you figured that out already :)

CE.

xekon
Just popping in
Just popping in
Posts: 14
Joined: Thu Jan 21, 2010 00:07

Re: Building Ogre 1.7 Project using Cegui 0.7.1 Linking error.

Postby xekon » Tue Jan 26, 2010 01:46

ahhh! ok, now I know how to find the lib I am missing by searching for the symbol! very cool, thank you!

my application is based on Xavier's Practical Application Example: http://test.ogitor.org/tiki/Practical+A ... et+Started

I am hoping to extend it using Ogre 1.7 and Cegui 0.7 Once I have it working I plan on making it available as an example, after having it critiqued for improvements/better ways to do things, if any.

now it builds/links successfully, but when I launch the application in VisualStudio with "start debugging" I got an unhandled exception and it breaks out at:

Code: Select all

        throw RendererException("Ogre was not initialised to automatically "
                                "create a window, you should therefore be "
                                "explicitly specifying a Ogre::RenderTarget in "
                                "the OgreRenderer::create function.");


so I took a look at that section in my code:

Code: Select all

   [b]CEGUI::OgreRenderer& myRenderer = CEGUI::OgreRenderer::create();[/b]


I believe the reason I am getting this problem stems from using "ogre->initialise(false);"
I actually use a loop at the end of main using "ogre->renderOneFrame();"

Code: Select all

    while (sim->getCurrentState() != SHUTDOWN) {
 
        handler->capture();
 
        // run the message pump (Eihort)
        Ogre::WindowEventUtilities::messagePump();
 
        ogre->renderOneFrame();
    }


at the top I have it set as: "Ogre::RenderWindow *window;"

so I added a line and modified my existing line:

Code: Select all

[b]
   // RenderTarget YAY!
   Ogre::RenderTarget *mRenderTarget = window;
   // Create an OgreRenderer object
   CEGUI::OgreRenderer& myRenderer = CEGUI::OgreRenderer::create(*mRenderTarget);
[/b]


this creates a different exception with ms_singleton:
Image

here is a copy of my main.cpp, in case I didn't provide enough information. I have a bad feeling that I am just not doing it correctly, I really hate it when i can't figure it out on my own, I obviously still have a lot to learn.

Code: Select all

#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"

#include "input.h"
#include "simulation.h"
 
#include "Ogre.h"
#include "OgreWindowEventUtilities.h"

// CEGUI includes
#include "CEGUI.h"
// needed to be able to create the CEGUI renderer interface
#include "RendererModules/Ogre/CEGUIOgreRenderer.h"
 
CEGUI::MouseButton convertButton(OIS::MouseButtonID buttonID)
{
 switch (buttonID)
 {
 case OIS::MB_Left:
     return CEGUI::LeftButton;

 case OIS::MB_Right:
     return CEGUI::RightButton;

 case OIS::MB_Middle:
     return CEGUI::MiddleButton;

 default:
     return CEGUI::LeftButton;
 }
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
#else
int main (int argc, char *argv[]) {
#endif
 
    Ogre::Root *ogre;
    Ogre::RenderWindow *window;
    Ogre::SceneManager *sceneMgr;
    Ogre::Camera *camera;
 
    // fire up an Ogre rendering window. Clearing the first two (of three) params will let us
    // specify plugins and resources in code instead of via text file
    ogre = new Ogre::Root("", "");
    // This is a VERY minimal rendersystem loading example; we are hardcoding the OpenGL
    // renderer, instead of loading GL and D3D9. We will add renderer selection support in a
    // future article.
 
    // I separate the debug and release versions of my plugins using the same "_d" suffix that
    // the Ogre main libraries use; you may need to remove the "_d" in your code, depending on the
    // naming convention you use
    // EIHORT NOTE: All Ogre DLLs use this suffix convention now -- #ifdef on the basis of the _DEBUG
    // define
#if defined(_DEBUG)
    ogre->loadPlugin("RenderSystem_GL_d");
#else
    ogre->loadPlugin("RenderSystem_GL");
#endif
    // we do this step just to get an iterator that we can use with setRenderSystem. In a future article
    // we actually will iterate the list to display which renderers are available.
   ogre->setRenderSystem(*ogre->getAvailableRenderers().begin());
   
    ogre->initialise(false);
 
    // load common plugins
#if defined(_DEBUG)
    ogre->loadPlugin("Plugin_CgProgramManager_d");       
    ogre->loadPlugin("Plugin_OctreeSceneManager_d");
#else
    ogre->loadPlugin("Plugin_CgProgramManager");       
    ogre->loadPlugin("Plugin_OctreeSceneManager");
#endif
    // load the basic resource location(s)
    Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
        "resource", "FileSystem", "General");
    Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
        "resource/gui.zip", "Zip", "GUI");
#if defined(WIN32_LEAN_AND_MEAN)
    Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
        "c:\\windows\\fonts", "FileSystem", "GUI");
#endif
 
    Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
    Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("GUI");
 
    // setup main window; hardcode some defaults for the sake of presentation
    Ogre::NameValuePairList opts;
    opts["resolution"] = "1024x768";
    opts["fullscreen"] = "false";
    opts["vsync"] = "false";
 
    // create a rendering window with the title "CDK"
    window = ogre->createRenderWindow("CDK", 1024, 768, false, &opts);
 
    // since this is basically a CEGUI app, we can use the ST_GENERIC scene manager for now; in a later article
    // we'll see how to change this
    sceneMgr = ogre->createSceneManager(Ogre::ST_GENERIC);
    camera = sceneMgr->createCamera("camera");
    camera->setNearClipDistance(5);
    Ogre::Viewport* vp = window->addViewport(camera);
    vp->setBackgroundColour(Ogre::ColourValue(0,0,0));
 
    // most examples get the viewport size to calculate this; for now, we'll just
    // set it to 4:3 the easy way
    camera->setAspectRatio((Ogre::Real)1.333333);
 
    // this next bit is for the sake of the input handler
    unsigned long hWnd;
    window->getCustomAttribute("WINDOW", &hWnd);
 
    // set up the input handlers
    Simulation *sim = new Simulation();
    InputHandler *handler = new InputHandler(sim, hWnd);
    sim->requestStateChange(SIMULATION);

   //CEGUI added

   // RenderTarget YAY!
   Ogre::RenderTarget *mRenderTarget = window;
   // Create an OgreRenderer object
   CEGUI::OgreRenderer& myRenderer = CEGUI::OgreRenderer::create(*mRenderTarget);

   //CEGUI added end
 
    while (sim->getCurrentState() != SHUTDOWN) {
 
        handler->capture();
 
        // run the message pump (Eihort)
        Ogre::WindowEventUtilities::messagePump();
 
        ogre->renderOneFrame();
    }
 
    // clean up after ourselves
    delete handler;
    delete sim;
    delete ogre;
 
    return 0;
}


EDIT: I can post the Call Stack, if that helps :oops:
If I follow the call stack down untill it get to the line in my code that triggered it, It's this line: "ogre->renderOneFrame();"

This line worked before adding the cegui lines, so I am thinking I need to modify this line to work with CEGUI, or maybe something needs to be done differently before getting to this line.

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

Re: Building Ogre 1.7 Project using Cegui 0.7.1 Linking error.

Postby CrazyEddie » Tue Jan 26, 2010 10:03

Hi,

It's because you're not setting up the CEGUI::System object (which you pass the Ogre specific renderer, image codec and resource provider objects). Because that over complicates things for most users, we provide a bootstrap function for this purpose. So where you have this:

Code: Select all

// Create an OgreRenderer object
   CEGUI::OgreRenderer& myRenderer = CEGUI::OgreRenderer::create(*mRenderTarget);

replace it with:

Code: Select all

// Create an OgreRenderer object
   CEGUI::OgreRenderer& myRenderer = CEGUI::OgreRenderer::bootstrapSystem(*mRenderTarget);

And all should be good.

HTH

CE.

Edited to fix function name.

xekon
Just popping in
Just popping in
Posts: 14
Joined: Thu Jan 21, 2010 00:07

Re: Building Ogre 1.7 Project using Cegui 0.7.1 Linking error.

Postby xekon » Tue Jan 26, 2010 19:10

CrazyEddie wrote:replace it with:

Code: Select all

// Create an OgreRenderer object
   CEGUI::OgreRenderer& myRenderer = CEGUI::OgreRenderer::bootstrap(*mRenderTarget);

And all should be good.


Thanks for the quick reply CrazyEddie! I tried it and it didn't work, but a quick trip to the documentation showed me the full function name. :) http://www.cegui.org.uk/docs/current/re ... orial.html (In case anyone comes to this thread looking for similar help.)

Code: Select all

   // Create an OgreRenderer object
   CEGUI::OgreRenderer& myRenderer = CEGUI::OgreRenderer::bootstrapSystem(*mRenderTarget);


Now That Everything build, runs, and closes without errors, I can add some more cegui stuff to the application. THANK YOU so much for helping me out.

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

Re: Building Ogre 1.7 Project using Cegui 0.7.1 Linking error.

Postby CrazyEddie » Wed Jan 27, 2010 09:35

:oops:

Sorry for getting the function name wrong. I'd actually checked the docs before posting as well :roll: I'll edit my post above so it has the correct function name.

Glad you have the basics in place now :)

CE.

xekon
Just popping in
Just popping in
Posts: 14
Joined: Thu Jan 21, 2010 00:07

Re: Building Ogre 1.7 Project using Cegui 0.7.1 Linking error.

Postby xekon » Thu Jan 28, 2010 08:43

Yes, thank you very much. now its just a matter of learning all the different functions and how to use them :) I've mostly been looking through the tutorials, although most tutorials are for 0.6.x some of it still applies to 0.7... and also the Developer Documentation has a lot of good information.

I really like tutorials :mrgreen:


Return to “Help”

Who is online

Users browsing this forum: No registered users and 11 guests