Linker errors with MyGUI::OgreRenderManager

siondream

26-02-2011 13:46:51

Hi there!

I've just installed MyGUI on my Ubuntu 10.10 with Ogre 1.7.1 and I'm very excited to use it in my final degree project. I was trying to get it running with a little example but there is a problem during the liking phase:


obj/game.o: In function `OgrePlatform':
/usr/local/include/MYGUI/MyGUI_OgrePlatform.h:28: undefined reference to `MyGUI::OgreRenderManager::OgreRenderManager()'
/usr/local/include/MYGUI/MyGUI_OgrePlatform.h:29: undefined reference to `MyGUI::OgreDataManager::OgreDataManager()'
obj/game.o: In function `MyGUI::OgrePlatform::initialise(Ogre::RenderWindow*, Ogre::SceneManager*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/local/include/MYGUI/MyGUI_OgrePlatform.h:46: undefined reference to `MyGUI::OgreRenderManager::initialise(Ogre::RenderWindow*, Ogre::SceneManager*)'
/usr/local/include/MYGUI/MyGUI_OgrePlatform.h:47: undefined reference to `MyGUI::OgreDataManager::initialise(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
obj/game.o: In function `MyGUI::OgrePlatform::shutdown()':
/usr/local/include/MYGUI/MyGUI_OgrePlatform.h:55: undefined reference to `MyGUI::OgreRenderManager::shutdown()'
/usr/local/include/MYGUI/MyGUI_OgrePlatform.h:56: undefined reference to `MyGUI::OgreDataManager::shutdown()'
collect2: ld returned 1 exit status
make: *** [dotscene] Error 1


I've installed MyGUI using CMake (activating Docs + Media + Tools + Static options). My makefile uses these linker flags among others:


-lMyGUIEngine -lMyGUI.OgrePlatform


On my /usr/local/lib I have the following files (among others):


libMyGUIEngine.so
libMyGUIEngine.so.3
libMyGUIEngine.so.3.0.1
libMyGUIEngineStatic.a
libMyGUI.OgrePlatform.a


Do you know the source of my problem?

Thank you very much.

Altren

26-02-2011 14:12:14

I guess you should use
-lMyGUIEngineStatic -lMyGUI.OgrePlatform

siondream

26-02-2011 14:17:29

I guess you should use
-lMyGUIEngineStatic -lMyGUI.OgrePlatform


I tried that but now it's worse because it doesn't recognise MyGUI's core:


obj/game.o: In function `~Game':
/home/david/programacion/iberogre-siontower/siontower/branches/mygui/src/game.cpp:104: undefined reference to `MyGUI::Gui::shutdown()'
/home/david/programacion/iberogre-siontower/siontower/branches/mygui/src/game.cpp:104: undefined reference to `MyGUI::Gui::shutdown()'
obj/game.o: In function `Game::initialiseMyGUI()':
/home/david/programacion/iberogre-siontower/siontower/branches/mygui/src/game.cpp:219: undefined reference to `MyGUI::Gui::Gui()'
/home/david/programacion/iberogre-siontower/siontower/branches/mygui/src/game.cpp:220: undefined reference to `MyGUI::Gui::initialise(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
obj/game.o: In function `OgrePlatform':
/usr/local/include/MYGUI/MyGUI_OgrePlatform.h:28: undefined reference to `MyGUI::OgreRenderManager::OgreRenderManager()'
/usr/local/include/MYGUI/MyGUI_OgrePlatform.h:29: undefined reference to `MyGUI::OgreDataManager::OgreDataManager()'
obj/game.o: In function `MyGUI::OgrePlatform::initialise(Ogre::RenderWindow*, Ogre::SceneManager*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/local/include/MYGUI/MyGUI_OgrePlatform.h:44: undefined reference to `MyGUI::LogManager::registerSection(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/local/include/MYGUI/MyGUI_OgrePlatform.h:46: undefined reference to `MyGUI::OgreRenderManager::initialise(Ogre::RenderWindow*, Ogre::SceneManager*)'
/usr/local/include/MYGUI/MyGUI_OgrePlatform.h:47: undefined reference to `MyGUI::OgreDataManager::initialise(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
obj/game.o: In function `MyGUI::OgrePlatform::shutdown()':
/usr/local/include/MYGUI/MyGUI_OgrePlatform.h:55: undefined reference to `MyGUI::OgreRenderManager::shutdown()'
/usr/local/include/MYGUI/MyGUI_OgrePlatform.h:56: undefined reference to `MyGUI::OgreDataManager::shutdown()'
/usr/local/include/MYGUI/MyGUI_OgrePlatform.h:59: undefined reference to `MyGUI::LogManager::unregisterSection(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: ld returned 1 exit status
make: *** [dotscene] Error 1


Before the problem was in OgreRenderer... Another idea?

Thanks anyway! :-)

Altren

26-02-2011 14:25:57

I wonder how you got libMyGUIEngine.so files, if you used static build, that generate only .a files. Also did you tried to compile demos/tools?

siondream

26-02-2011 14:31:39

I wonder how you got libMyGUIEngine.so files, if you used static build, that generate only .a files. Also did you tried to compile demos/tools?

I've buit and installed MyGUI a couple times. The first time I chose the non static version and I had libMyGUIEngine.so and libMyGUI.OgrePlatform.a (why static?). The second time I had the libMyGUIEngine.a file.

Edit: The second time I chose the static approach because I found it in a forum as an anwser to a similar problem.

Altren

26-02-2011 14:48:14

I looked through CMake link commands and found next:
-rdynamic ../../lib/libMyGUI.OgrePlatform.a ../../lib/libMyGUIEngineStatic.a -lOIS -lOgreMain -lfreetypeI forgot to mention, that you also need to link freetype when you use static lib. And actually I don't know what rdynamic is used for, but you can try it too.

siondream

26-02-2011 14:51:50

I looked through CMake link commands and found next:
-rdynamic ../../lib/libMyGUI.OgrePlatform.a ../../lib/libMyGUIEngineStatic.a -lOIS -lOgreMain -lfreetypeFirst 0 I forgot to mention, that you also need to link freetype when you use static lib. And actually I don't know what rdynamic is used for, but you can try it too.


I added -lfreetype to link flags but it doesn't change anything :(

Altren

26-02-2011 14:57:02

Proper linker options are
-lMyGUI.OgrePlatform -lMyGUIEngineStatic -lfreetype note that order might be important too.

siondream

26-02-2011 15:32:32

Proper linker options are
-lMyGUI.OgrePlatform -lMyGUIEngineStatic -lfreetype note that order might be important too.


With those I was getting the same error so I decided to erase MyGUI and reinstall. When I chose static build it won't compile (error at 60%):

/home/david/programacion/MyGUI3.0/MyGUIEngine/include/MyGUI_IWidgetFactory.h: In constructor ‘MyGUI::factory::BaseWidgetFactory<T>::BaseWidgetFactory()’:
/home/david/programacion/MyGUI3.0/MyGUIEngine/include/MyGUI_IWidgetFactory.h:60: error: ‘class MyGUI::WidgetManager’ has no member named ‘registerFactory’
/home/david/programacion/MyGUI3.0/MyGUIEngine/include/MyGUI_IWidgetFactory.h: In destructor ‘MyGUI::factory::BaseWidgetFactory<T>::~BaseWidgetFactory()’:
/home/david/programacion/MyGUI3.0/MyGUIEngine/include/MyGUI_IWidgetFactory.h:67: error: ‘class MyGUI::WidgetManager’ has no member named ‘unregisterFactory’
make[2]: *** [MyGUIEngine/CMakeFiles/MyGUIEngine.dir/src/MyGUI_WidgetManager.cpp.o] Error 1
make[1]: *** [MyGUIEngine/CMakeFiles/MyGUIEngine.dir/all] Error 2
make: *** [all] Error 2


Then I chose again the non static version and the following linker flags (in that order):

-lMyGUI.OgrePlatform -lMyGUIEngine -lfreetype

I still have problems in OgrePlatform:

obj/game.o: In function `OgrePlatform':
/usr/local/include/MYGUI/MyGUI_OgrePlatform.h:28: undefined reference to `MyGUI::OgreRenderManager::OgreRenderManager()'
/usr/local/include/MYGUI/MyGUI_OgrePlatform.h:29: undefined reference to `MyGUI::OgreDataManager::OgreDataManager()'
obj/game.o: In function `MyGUI::OgrePlatform::initialise(Ogre::RenderWindow*, Ogre::SceneManager*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/local/include/MYGUI/MyGUI_OgrePlatform.h:46: undefined reference to `MyGUI::OgreRenderManager::initialise(Ogre::RenderWindow*, Ogre::SceneManager*)'
/usr/local/include/MYGUI/MyGUI_OgrePlatform.h:47: undefined reference to `MyGUI::OgreDataManager::initialise(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
obj/game.o: In function `MyGUI::OgrePlatform::shutdown()':
/usr/local/include/MYGUI/MyGUI_OgrePlatform.h:55: undefined reference to `MyGUI::OgreRenderManager::shutdown()'
/usr/local/include/MYGUI/MyGUI_OgrePlatform.h:56: undefined reference to `MyGUI::OgreDataManager::shutdown()'
collect2: ld returned 1 exit status
make: *** [dotscene] Error 1


Thanks.

Altren

26-02-2011 16:01:53

Oh, I just noticed that you use very old version of MyGUI. Please download MyGUI 3.2.0 RC1 or grab code from svn.

siondream

26-02-2011 17:02:33

Oh, I just noticed that you use very old version of MyGUI. Please download MyGUI 3.2.0 RC1 or grab code from svn.

I've installed MyGUI 3.2.0 RC1 and the problem continues. I don't know if I'm doing something wrong. The code is the same and the linker flags too (I used the non static instalation).

Altren

26-02-2011 18:34:48

Did you tried to compile and run LayoutEditor or any demo?

Altren

26-02-2011 19:16:22

I just tried to write small app and it compiles fine with both static and dynamic versions of MyGUI. Ubuntu 10.10, gcc 4.4.5, x64.
Dynamic:
g++ main.cpp -lOgreMain -I /home/altren/trunk/MyGUIEngine/include/ -I /home/altren/trunk/Platforms/Ogre/OgrePlatform/include/
-L /home/altren/builds/mygui_ogre/lib/ -lMyGUIEngine -lMyGUI.OgrePlatform -I /usr/include/OGRE/

Static:
g++ main.cpp -lOgreMain -I /home/altren/trunk/MyGUIEngine/include/ -I /home/altren/trunk/Platforms/Ogre/OgrePlatform/include/
-L /home/altren/builds/mygui_ogre_static/lib/ -lMyGUIEngineStatic -lMyGUI.OgrePlatform -I /usr/include/OGRE/


You should remove all previously installed libs and headers from /usr and /usr/local folders.

siondream

27-02-2011 00:15:23

I'm thrilled because I've followed your instructions and the error is still the same... I don't know what to do...

Before the local test, my makefile looked like this:


# Nombre del proyecto
PROYECTO := dotscene

# Directorios
OBJDIR := obj
SRCDIR := src
HDRDIR := include

#Compilador y flags
CXX := g++
CXXFLAGS := -Wall `pkg-config --cflags OGRE` -fexceptions -I$(HDRDIR)

#Fichero de dependencias
DEPFILE := dependencias

# Flags del enlazador
LDFLAGS := `pkg-config --libs OGRE` -L/bin/Debug -L/bin/Release -s
LDFLAGS += -lGL -lstdc++ -lOgreMain -lOIS -L/usr/local/lib/libMyGUI.OgrePlatform -lMyGUI.OgrePlatform -lMyGUIEngine -lfreetype
LDFLAGS += -lSDL -lSDL_mixer

# Colores para la salida de consola
COLOR_FIN := \033[00m
COLOR_OK := \033[01;32m
COLOR_ERROR := \033[01;31m
COLOR_AVISO := \033[01;33m
COLOR_COMP := \033[01;34m
COLOR_ENL := \033[01;35m

# Modo de compilación, por defecto debug
ifeq ($(modo), release)
CXXFLAGS += -O2 -D_RELEASE
else
modo := debug
CXXFLAGS += -g -D_DEBUG
endif

# Seleccionamos ficheros fuente
SRCS := $(notdir $(shell ls -t $(SRCDIR)/*.cpp))
OBJS := $(addprefix $(OBJDIR)/, $(addsuffix .o,$(basename $(SRCS))))

.PHONY:all
all: informacion gen_deps $(PROYECTO)

# Comprobamos el modo de compilación
informacion:
ifneq ($(modo),release)
ifneq ($(modo),debug)
@echo ''
@echo -e '$(COLOR_ERROR)Modo de compilación inválido.$(COLOR_FIN)'
@echo "Por favor usa 'make [modo=release|debug]'"
@echo ''
@exit 1
endif
endif
@echo ''
@echo -e 'Compilando en modo $(COLOR_AVISO)"$(modo)"$(COLOR_FIN)'
@echo '..........................'
@echo ''

gen_deps:
@echo ''
@echo -e '$(COLOR_AVISO)Generando dependencias$(COLOR_FIN)...'
@gcc -MM -I$(HDRDIR) $(shell ls -t $(SRCDIR)/*.cpp) | sed 's/^\([a-zA-Z]\+.o:\)/$(OBJDIR)\/\1/g' > $(DEPFILE)
@echo ''

# Compilación
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
@echo -e '$(COLOR_COMP)Compilando$(COLOR_FIN)... $(notdir $<)'
@mkdir -p $(OBJDIR)
@$(CXX) $(CXXFLAGS) -c $< -o $@

# Enlazado
$(PROYECTO): $(OBJS)
@echo ''
@echo -e '$(COLOR_ENL)Enlazando$(COLOR_FIN)...'
@echo ''
@$(CXX) $(LDFLAGS) -o $@ $^ $(LIBS)
@echo -e '$(COLOR_OK)Terminado.$(COLOR_FIN)'
@echo ''

# Limpiado del directorio
.PHONY:clean
clean:
@echo ''
@echo -e '$(COLOR_AVISO)Limpiando$(COLOR_FIN)...'
@echo ''
rm $(DEPFILE) $(OBJS) $(PROYECTO) $(OBJDIR) *~ -rf
@echo ''
@echo -e '$(COLOR_OK)Terminado.$(COLOR_FIN)'
@echo ''

-include $(DEPFILE)


Here are my little piece of code where I used MyGUI (just initialisation):


bool Game::initialiseMyGUI() {
_ogrePlatform = new MyGUI::OgrePlatform();
_ogrePlatform->initialise(_window, _sceneManager);
_gui = new MyGUI::Gui();
_gui->initialise();

return true;
}

Game::~Game() {

...

// Destruimos MYGUI
_gui->shutdown();
delete _gui;
_gui = 0;
_ogrePlatform->shutdown();
delete _ogrePlatform;
_ogrePlatform = 0;

...

}


By the way, thank you very much for all yout help.

Altren

27-02-2011 00:38:39

Try to replace compilation command
@$(CXX) $(CXXFLAGS) -c $< -o $@with@$(CXX) $(CXXFLAGS) $(LDFLAGS) -c $< -o $@

siondream

27-02-2011 09:24:35

I''ve replaced the compilation command and still the problem persists... I really don't know what to do...

EDIT: I've installed the Demos and Tools and they run correctly...

EDIT 2: If you post your little sample project somewhere (megaupload, mail or whatever) I could easily check if it builds on my system. That way we could discard any installation pitfalls. Thank you very much.

Altren

27-02-2011 20:47:12

I took code there (http://www.ogre3d.org/tikiwiki/MadMarx+ ... =Tutorials) and just added several lines. Code itself is not really correct, but it use classes and member functions that you have problems with. Here's my sources: http://www.everfall.com/paste/id.php?ws6ejjg4e2az

siondream

28-02-2011 00:34:14

And what makefile do you use? I'm trying to compile that code but I get the same error message. If you could just post a working makefile I would be really grateful.

Thanks.

Altren

28-02-2011 09:37:56

I was using simple command above. If you got same error message as before, then this mean that you have problem with installed versions.I just tried to write small app and it compiles fine with both static and dynamic versions of MyGUI. Ubuntu 10.10, gcc 4.4.5, x64.
Dynamic:
g++ main.cpp -lOgreMain -I /home/altren/trunk/MyGUIEngine/include/ -I /home/altren/trunk/Platforms/Ogre/OgrePlatform/include/
-L /home/altren/builds/mygui_ogre/lib/ -lMyGUIEngine -lMyGUI.OgrePlatform -I /usr/include/OGRE/

Static:
g++ main.cpp -lOgreMain -I /home/altren/trunk/MyGUIEngine/include/ -I /home/altren/trunk/Platforms/Ogre/OgrePlatform/include/
-L /home/altren/builds/mygui_ogre_static/lib/ -lMyGUIEngineStatic -lMyGUI.OgrePlatform -I /usr/include/OGRE/


You should remove all previously installed libs and headers from /usr and /usr/local folders.

siondream

28-02-2011 13:19:04

Okey, that works but my makefile doesn't. Thank you very much for your help, it's hugely appreciated, I'll investigate this problem further.