[Solved] Undefined Reference with CEGUI

Skuisy

30-04-2016 13:31:48

Hey everyone,

I'm trying to make a program with ogre3D and CEGUI.

I'm compiling my project thank's to this cmake: http://pastebin.com/idCLSwyi

And another cmake to find CEGUI: http://pastebin.com/X8zKJGt1

All seems good when I cmake the project.

But when i try to make, I got this error:
undefined reference to `CEGUI::OgreRenderer::bootstrapSystem(int)'

My includes:
#include <CEGUI/CEGUI.h>
#include <CEGUI/RendererModules/Ogre/Renderer.h>

I'm using CEGUI 0.8.6 and Ogre 1.10.

Has anyone ever had this error ? Or may be someone know how to solve it ? Thank's in advance.

Ident

30-04-2016 16:58:36

When you have issues it is good to also always report the OS, compiler (including version) and the full error log from the output.

Your issue is most likely that the CEGUI library is not linked (taken from the info you provided). Check the project settings and see if you are linking the CEGUI libraries.

Where are the CMake files from? There is also a CEGUIFind cmake on the CEGUI repo.

Skuisy

30-04-2016 18:18:26

Hey,

I'm on linux (Elementary OS) and my compiler is " gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.1) ".

Here is the full error:

Scanning dependencies of target OgreApp
[ 33%] Building CXX object CMakeFiles/OgreApp.dir/src/Menu.cpp.o
[ 66%] Building CXX object CMakeFiles/OgreApp.dir/src/InputListener.cpp.o
Linking CXX executable dist/bin/OgreApp
CMakeFiles/OgreApp.dir/src/Menu.cpp.o: In function `Menu::createScene()':
/home/octeau_j/Epitech/CPP/cpp_indie_studio/jeremy/bomberman/bomber_app/src/Menu.cpp:117: undefined reference to `CEGUI::OgreRenderer::bootstrapSystem(int)'
collect2: error: ld returned 1 exit status
make[2]: *** [dist/bin/OgreApp] Error 1
make[1]: *** [CMakeFiles/OgreApp.dir/all] Error 2
make: *** [all] Error 2


And the function:

void Menu::createScene()
{
mSceneMgr->setAmbientLight(Ogre::ColourValue(1.0, 1.0, 1.0));
mRenderer = &CEGUI::OgreRenderer::bootstrapSystem();
CEGUI::ImageManager::setImagesetDefaultResourceGroup("Imagesets");
CEGUI::Font::setDefaultResourceGroup("Fonts");
CEGUI::Scheme::setDefaultResourceGroup("Schemes");
CEGUI::WidgetLookManager::setDefaultResourceGroup("LookNFeel");
CEGUI::WindowManager::setDefaultResourceGroup("Layouts");
}


This is my working directory call "bomber_app":
.
├── CMakeLists.txt
├── cmake_modules
│   └── FindCEGUI.cmake
├── dist
│   ├── bin
│   │   ├── plugins.cfg
│   │   └── resources.cfg
│   └── media
│   ├── materials
│   │   ├── scripts
│   │   └── textures
│   ├── models
│   └── packs
├── include
│   ├── InputListener.hh
│   └── Menu.hh
└── src
├── InputListener.cpp
├── main.cpp
└── Menu.cpp


and i'm compiling into another directory called : "bomber_build" by doing this command:
cmake ../bomber_app
The first cmake come from the tutoriel of Ogre3D and the FindCEGUI.cmake from the official repository of CEGUI.
And i think he is working, because when i cmake the project i got:
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for OGRE...
-- OGRE_PREFIX_WATCH changed.
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.26")
-- checking for module 'OGRE'
-- found OGRE, version 1.10.0unstable
-- Found Ogre Xalafu (1.10.0)
-- Found OGRE: /usr/local/lib/libOgreMain.so
-- Looking for OGRE_Paging...
-- Found OGRE_Paging: /usr/local/lib/libOgrePaging.so
-- Looking for OGRE_Terrain...
-- Found OGRE_Terrain: /usr/local/lib/libOgreTerrain.so
-- Looking for OGRE_Property...
-- Found OGRE_Property: /usr/local/lib/libOgreProperty.so
-- Looking for OGRE_RTShaderSystem...
-- Found OGRE_RTShaderSystem: /usr/local/lib/libOgreRTShaderSystem.so
-- Looking for OGRE_Volume...
-- Found OGRE_Volume: /usr/local/lib/libOgreVolume.so
-- Looking for OGRE_Overlay...
-- Found OGRE_Overlay: /usr/local/lib/libOgreOverlay.so
-- Looking for OGRE_MeshLodGenerator...
-- Found OGRE_MeshLodGenerator: /usr/local/lib/libOgreMeshLodGenerator.so
-- Looking for OGRE_HLMS...
-- Found OGRE_HLMS: /usr/local/lib/libOgreHLMS.so
-- Looking for OIS...
-- OIS_PREFIX_PATH changed.
-- checking for module 'OIS'
-- found OIS, version 1.3.0
-- Found OIS: /usr/lib/x86_64-linux-gnu/libOIS.so
-- Looking for CEGUI...
-- Found CEGUI (0.8.6)
-- Found CEGUI: optimized;/usr/local/lib/libCEGUIBase-0.so;debug;/usr/local/lib/libCEGUIBase-0.so
-- Looking for CEGUI_CommonDialogs...
-- Found CEGUI_CommonDialogs: optimized;/usr/local/lib/libCEGUICommonDialogs-0.so;debug;/usr/local/lib/libCEGUICommonDialogs-0.so
-- Looking for CEGUI_CoreWindowRendererSet...
-- Found CEGUI_CoreWindowRendererSet: optimized;/usr/local/lib/cegui-0.8/libCEGUICoreWindowRendererSet.so;debug;/usr/local/lib/cegui-0.8/libCEGUICoreWindowRendererSet.so
-- Looking for CEGUI_Direct3D9Renderer...
-- Could not locate CEGUI_Direct3D9Renderer
-- Looking for CEGUI_Direct3D10Renderer...
-- Could not locate CEGUI_Direct3D10Renderer
-- Looking for CEGUI_Direct3D11Renderer...
-- Could not locate CEGUI_Direct3D11Renderer
-- Looking for CEGUI_DirectFBRenderer...
-- Could not locate CEGUI_DirectFBRenderer
-- Looking for CEGUI_IrrlichtRenderer...
-- Could not locate CEGUI_IrrlichtRenderer
-- Looking for CEGUI_NullRenderer...
-- Could not locate CEGUI_NullRenderer
-- Looking for CEGUI_OgreRenderer...
-- Found CEGUI_OgreRenderer: optimized;/usr/local/lib/libCEGUIOgreRenderer-0.so;debug;/usr/local/lib/libCEGUIOgreRenderer-0.so
-- Looking for CEGUI_OpenGLRenderer...
-- Found CEGUI_OpenGLRenderer: optimized;/usr/local/lib/libCEGUIOpenGLRenderer-0.so;debug;/usr/local/lib/libCEGUIOpenGLRenderer-0.so

-- Looking for CEGUI_OpenGL3Renderer...
-- Could not locate CEGUI_OpenGL3Renderer
-- Looking for CEGUI_OpenGLESRenderer...
-- Could not locate CEGUI_OpenGLESRenderer
-- Looking for CEGUI_CoronaImageCodec...
-- Could not locate CEGUI_CoronaImageCodec
-- Looking for CEGUI_DevILImageCodec...
-- Found CEGUI_DevILImageCodec: optimized;/usr/local/lib/cegui-0.8/libCEGUIDevILImageCodec.so;debug;/usr/local/lib/cegui-0.8/libCEGUIDevILImageCodec.so
-- Looking for CEGUI_FreeImageImageCodec...
-- Found CEGUI_FreeImageImageCodec: optimized;/usr/local/lib/cegui-0.8/libCEGUIFreeImageImageCodec.so;debug;/usr/local/lib/cegui-0.8/libCEGUIFreeImageImageCodec.so
-- Looking for CEGUI_SILLYImageCodec...
-- Could not locate CEGUI_SILLYImageCodec
-- Looking for CEGUI_STBImageCodec...
-- Could not locate CEGUI_STBImageCodec
-- Looking for CEGUI_TGAImageCodec...
-- Could not locate CEGUI_TGAImageCodec
-- Looking for CEGUI_PVRImageCodec...
-- Could not locate CEGUI_PVRImageCodec
-- Looking for CEGUI_ExpatParser...
-- Found CEGUI_ExpatParser: optimized;/usr/local/lib/cegui-0.8/libCEGUIExpatParser.so;debug;/usr/local/lib/cegui-0.8/libCEGUIExpatParser.so
-- Looking for CEGUI_LibXMLParser...
-- Could not locate CEGUI_LibXMLParser
-- Looking for CEGUI_RapidXMLParser...
-- Could not locate CEGUI_RapidXMLParser
-- Looking for CEGUI_TinyXMLParser...
-- Could not locate CEGUI_TinyXMLParser
-- Looking for CEGUI_XercesParser...
-- Could not locate CEGUI_XercesParser
-- Looking for CEGUI_LuaScriptModule...
-- Could not locate CEGUI_LuaScriptModule
-- Configuring done
-- Generating done
-- Build files have been written to: /home/octeau_j/Epitech/CPP/cpp_indie_studio/jeremy/bomberman/bomber_app


The red lines show that the CEGUIOgreRenderer is linked no ?

Thank's in advance.

Ident

30-04-2016 23:10:46

Thanks for the extra info.

I am doing Windows support so I can't tell you what to do, but what I can tell you is that the CMake message of CEGUI being found is no guarantee of it being linked correctly, it just means literally that it founds the files (including the so files) but makes no statement on usage. You should verify if it is linked in your resulting project, from what you showed us it looks like it is not. If it is not then we must look into why this is the case and repair that. As I said, I don't know your setup so I don't know how you can check if it is linked in your project.

YaronCT

01-05-2016 07:53:58

Skuisy: u need to also link to "${CEGUI_OgreRenderer_LIBRARIES}". In "CMakeLists.txt", Add it (without the double quotation marks) to the list of libraries to link with in:

target_link_libraries(OgreApp ${OGRE_LIBRARIES} ${OIS_LIBRARIES} ${OGRE_Overlay_LIBRARIES} ${CEGUI_LIBRARIES}))

Skuisy

01-05-2016 10:38:09

oh, i feel so silly ... I don't know how i haven't not seen this missing link ...

A big thank you to YaronCT.

The problem is solved now.

Ident

01-05-2016 10:38:59

Where is that CMake file you used from? Can we update it wherever it was offered?

Skuisy

01-05-2016 10:54:44

I just took the cmake from this tutoriel and just add some rules that CEGUI need:
http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Building+Your+Projects+With+CMake

And the FindCEGUI.cmake in this repository:
https://bitbucket.org/cegui/cegui/src/b975a6885624277808189ac3d503dea7ba82b1a7/cmake/?at=v0-8

Ident

01-05-2016 10:56:43

Do you think it would make sense to put your update Cmake file somewhere like here: http://cegui.org.uk/wiki/Building_CEGUI ... reRenderer for other users?

Skuisy

01-05-2016 11:39:26

Oh yes but I'm not sure that my cmake is perfect :roll: !

At least put a link of the FindCEGUI.cmake and how to link it with the cmake of Ogre3D ! It can be very helpful !

Ident

01-05-2016 11:46:57

I assume this is your final Cmake file that worked, including the fix suggested by yaron:

#/*
#-----------------------------------------------------------------------------
#Filename: CMakeLists.txt
#-----------------------------------------------------------------------------
#
#This source file is part of the
# ___ __ __ _ _ _
# /___\__ _ _ __ ___ / / /\ \ (_) | _(_)
# // // _` | '__/ _ \ \ \/ \/ / | |/ / |
#/ \_// (_| | | | __/ \ /\ /| | <| |
#\___/ \__, |_| \___| \/ \/ |_|_|\_\_|
# |___/
# Tutorial Framework
# http://www.ogre3d.org/tikiwiki/
#-----------------------------------------------------------------------------
#*/
cmake_minimum_required(VERSION 2.6)

project(bomberman)

if(WIN32)
set(CMAKE_MODULE_PATH "$ENV{OGRE_HOME}/CMake/;${CMAKE_MODULE_PATH}")
set(OGRE_SAMPLES_INCLUDEPATH
$ENV{OGRE_HOME}/Samples/include
)
endif(WIN32)

if(UNIX)
if(EXISTS "/usr/local/lib/OGRE/cmake")

set(CMAKE_MODULE_PATH "/usr/local/lib/OGRE/cmake/;${CMAKE_MODULE_PATH}")
set(OGRE_SAMPLES_INCLUDEPATH "/usr/local/share/OGRE/samples/Common/include/") # We could just *assume* that developers uses this basepath : /usr/local

elseif(EXISTS "/usr/lib/OGRE/cmake")

set(CMAKE_MODULE_PATH "/usr/lib/OGRE/cmake/;${CMAKE_MODULE_PATH}")
set(OGRE_SAMPLES_INCLUDEPATH "/usr/share/OGRE/samples/Common/include/") # Otherwise, this one

else ()
message(SEND_ERROR "Failed to find module path.")
endif()
endif(UNIX)

if (CMAKE_BUILD_TYPE STREQUAL "")
# CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up
# differentiation between debug and release builds.
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None (CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif ()

set(CMAKE_DEBUG_POSTFIX "_d")

set(CMAKE_CXX_FLAGS "-std=c++11 -Wall")

set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/dist")

find_package(OGRE REQUIRED)

#if(NOT "${OGRE_VERSION_NAME}" STREQUAL "Cthugha")
# message(SEND_ERROR "You need Ogre 1.7 Cthugha to build this.")
#endif()

find_package(OIS REQUIRED)

if(NOT OIS_FOUND)
message(SEND_ERROR "Failed to find OIS.")
endif()

# Find Boost
if (NOT OGRE_BUILD_PLATFORM_IPHONE)
if (WIN32 OR APPLE)
set(Boost_USE_STATIC_LIBS TRUE)
else ()
# Statically linking boost to a dynamic Ogre build doesn't work on Linux 64bit
set(Boost_USE_STATIC_LIBS ${OGRE_STATIC})
endif ()
if (MINGW)
# this is probably a bug in CMake: the boost find module tries to look for
# boost libraries with name libboost_*, but CMake already prefixes library
# search names with "lib". This is the workaround.
set(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} "")
endif ()
set(Boost_ADDITIONAL_VERSIONS "1.44" "1.44.0" "1.42" "1.42.0" "1.41.0" "1.41" "1.40.0" "1.40" "1.39.0" "1.39" "1.38.0" "1.38" "1.37.0" "1.37" )
# Components that need linking (NB does not include header-only components like bind)
set(OGRE_BOOST_COMPONENTS thread date_time)

find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET)
if (NOT Boost_FOUND)
# Try again with the other type of libs
set(Boost_USE_STATIC_LIBS NOT ${Boost_USE_STATIC_LIBS})
find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET)
endif()
find_package(Boost QUIET)

# Set up referencing of Boost
include_directories(${Boost_INCLUDE_DIR})
add_definitions(-DBOOST_ALL_NO_LIB)
set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${Boost_LIBRARIES})
endif()

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules/;${CMAKE_MODULE_PATH}")
find_package(CEGUI REQUIRED OGRE)

if(NOT CEGUI_FOUND)
message(SEND_ERROR "Failed to find CEGUI.")
endif()

set(HDRS
)

set(SRCS
./src/main.cpp
./src/Menu.cpp
./src/InputListener.cpp
)

set(INCLUDE_DIRECTORY
./include
)

include_directories( ${OIS_INCLUDE_DIRS}
${OGRE_INCLUDE_DIRS}
${OGRE_SAMPLES_INCLUDEPATH}
${OGRE_Overlay_INCLUDE_DIRS}
${CEGUI_INCLUDE_DIRS}
${INCLUDE_DIRECTORY}
)

add_executable(OgreApp WIN32 ${HDRS} ${SRCS})

set_target_properties(OgreApp PROPERTIES DEBUG_POSTFIX _d)

target_link_libraries(OgreApp ${OGRE_LIBRARIES} ${OIS_LIBRARIES} ${OGRE_Overlay_LIBRARIES} ${CEGUI_LIBRARIES} ${CEGUI_OgreRenderer_LIBRARIES})

file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dist/bin)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dist/media)

# post-build copy for win32
if(WIN32 AND NOT MINGW)
add_custom_command( TARGET OgreApp PRE_BUILD
COMMAND if not exist .\\dist\\bin mkdir .\\dist\\bin )
add_custom_command( TARGET OgreApp POST_BUILD
COMMAND copy \"$(TargetPath)\" .\\dist\\bin )
endif(WIN32 AND NOT MINGW)

if(MINGW OR UNIX)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/dist/bin)
endif(MINGW OR UNIX)

if(WIN32)

install(TARGETS OgreApp
RUNTIME DESTINATION bin
CONFIGURATIONS All)

install(DIRECTORY ${CMAKE_SOURCE_DIR}/dist/Media
DESTINATION ./
CONFIGURATIONS Release RelWithDebInfo Debug
)

install(FILES ${CMAKE_SOURCE_DIR}/dist/bin/plugins.cfg
${CMAKE_SOURCE_DIR}/dist/bin/resources.cfg
DESTINATION bin
CONFIGURATIONS Release RelWithDebInfo
)

install(FILES ${CMAKE_SOURCE_DIR}/dist/bin/plugins_d.cfg
${CMAKE_SOURCE_DIR}/dist/bin/resources_d.cfg
DESTINATION bin
CONFIGURATIONS Debug
)

# NOTE: for the 1.7.1 sdk the OIS dll is called OIS.dll instead of libOIS.dll
# so you'll have to change that to make it work with 1.7.1
install(FILES ${OGRE_PLUGIN_DIR_REL}/OgreMain.dll
${OGRE_PLUGIN_DIR_REL}/RenderSystem_Direct3D9.dll
${OGRE_PLUGIN_DIR_REL}/RenderSystem_GL.dll
${OGRE_PLUGIN_DIR_REL}/libOIS.dll
DESTINATION bin
CONFIGURATIONS Release RelWithDebInfo
)

install(FILES ${OGRE_PLUGIN_DIR_DBG}/OgreMain_d.dll
${OGRE_PLUGIN_DIR_DBG}/RenderSystem_Direct3D9_d.dll
${OGRE_PLUGIN_DIR_DBG}/RenderSystem_GL_d.dll
${OGRE_PLUGIN_DIR_DBG}/libOIS_d.dll
DESTINATION bin
CONFIGURATIONS Debug
)

# as of sdk 1.7.2 we need to copy the boost dll's as well
# because they're not linked statically (it worked with 1.7.1 though)
install(FILES ${Boost_DATE_TIME_LIBRARY_RELEASE}
${Boost_THREAD_LIBRARY_RELEASE}
DESTINATION bin
CONFIGURATIONS Release RelWithDebInfo
)

install(FILES ${Boost_DATE_TIME_LIBRARY_DEBUG}
${Boost_THREAD_LIBRARY_DEBUG}
DESTINATION bin
CONFIGURATIONS Debug
)
endif(WIN32)

if(UNIX)

install(TARGETS OgreApp
RUNTIME DESTINATION bin
CONFIGURATIONS All)

install(DIRECTORY ${CMAKE_SOURCE_DIR}/dist/media
DESTINATION ./
CONFIGURATIONS Release RelWithDebInfo Debug
)

install(FILES ${CMAKE_SOURCE_DIR}/dist/bin/plugins.cfg
${CMAKE_SOURCE_DIR}/dist/bin/resources.cfg
DESTINATION bin
CONFIGURATIONS Release RelWithDebInfo Debug
)

endif(UNIX)

Skuisy

01-05-2016 12:42:43

Exactly,

To sum up from te original cmake comes with the tuto:

I changed:
endif(EXISTS "/usr/local/lib/OGRE")

by:
endif()

Then I write thoses bolds lines:
set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${Boost_LIBRARIES})
endif()

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules/;${CMAKE_MODULE_PATH}")
find_package(CEGUI REQUIRED)

if(NOT CEGUI_FOUND)
message(SEND_ERROR "Failed to find CEGUI.")
endif()


set(HDRS
./TutorielApplication.h


Update the include directories:
include_directories( ${OIS_INCLUDE_DIRS}
${OGRE_INCLUDE_DIRS}
${OGRE_SAMPLES_INCLUDEPATH}
${CEGUI_INCLUDE_DIRS}
)


AND what I forgot to do. Add the differents links to library:
target_link_libraries(OgreApp ${OGRE_LIBRARIES} ${OIS_LIBRARIES} ${OGRE_Overlay_LIBRARIES} ${CEGUI_LIBRARIES} ${CEGUI_OgreRenderer_LIBRARIES}


Finally add the FindCEGUI.cmake that you can find int this repository : https://bitbucket.org/cegui/cegui/src/b975a6885624277808189ac3d503dea7ba82b1a7/cmake/?at=v0-8
Just like that:
.
├── CMakeLists.txt
├── cmake_modules
│   └── FindCEGUI.cmake


That's what i did

Ident

01-05-2016 12:50:12

I added some info here http://cegui.org.uk/wiki/Building_CEGUI ... reRenderer under "Optional: If you want to use CMake to set up your own project"

Skuisy

01-05-2016 12:57:06

Why add this on "Building_CEED_for_Windows" when I'm on Linux ?

Why not just a link after how to build it on Unix system : http://cegui.org.uk/wiki/Building_CEGUI_for_Ogre_/_OgreRenderer ?

Ident

01-05-2016 13:17:39

That's actually where I had put it, I just poste the wrong link -> fixed the link.

Skuisy

01-05-2016 13:49:55

Thank's for helping me !

See you !