Issue with Static Linking of CEGUI v0.7.1 - Linux

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

User avatar
fero
Just popping in
Just popping in
Posts: 5
Joined: Thu Aug 05, 2010 19:22
Location: Orlando, FL

Issue with Static Linking of CEGUI v0.7.1 - Linux

Postby fero » Thu Aug 05, 2010 20:27

Hello,

I am currently integrating CEGUI v0.7.1 into my OpenGL application and I am running into some difficulties with the final linking process on my application side.

Code: Select all

/home/fero/code/P3/CEGUI-0.7.1/lib/libCEGUIBase.a(libCEGUIBase_la-CEGUIScheme.o)(.text+0x585): In function `CEGUI::Scheme::loadWindowRendererFactories()':
/usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/stl_iterator.h:614: undefined reference to `getWindowRendererModule'
/home/fero/code/P3/CEGUI-0.7.1/lib/libCEGUIBase.a(libCEGUIBase_la-CEGUISystem.o)(.text+0x19bb): In function `CEGUI::System::setupXMLParser()':
/home/fero/code/P3/CEGUI-0.7.1/cegui/src/CEGUISystem.cpp:1521: undefined reference to `createParser'
/home/fero/code/P3/CEGUI-0.7.1/lib/libCEGUIBase.a(libCEGUIBase_la-CEGUISystem.o)(.text+0x1a73): In function `CEGUI::System::cleanupXMLParser()':
/home/fero/code/P3/CEGUI-0.7.1/cegui/src/CEGUISystem.cpp:1562: undefined reference to `destroyParser'
/home/fero/code/P3/CEGUI-0.7.1/lib/libCEGUIBase.a(libCEGUIBase_la-CEGUISystem.o)(.text+0x1f39): In function `CEGUI::System::cleanupImageCodec()':
/home/fero/code/P3/CEGUI-0.7.1/cegui/src/CEGUISystem.cpp:1733: undefined reference to `destroyImageCodec'
/home/fero/code/P3/CEGUI-0.7.1/lib/libCEGUIBase.a(libCEGUIBase_la-CEGUISystem.o)(.text+0x1f90): In function `CEGUI::System::setupImageCodec(CEGUI::String const&)':
/home/fero/code/P3/CEGUI-0.7.1/cegui/src/CEGUISystem.cpp:1700: undefined reference to `createImageCodec'
collect2: ld returned 1 exit status


CEGUI is able to make and install with no problems in a static configuration using the following configure line:

Code: Select all

sh configure --prefix="/home/fero/code/P3/CEGUI-0.7.1" --enable-debug --enable-static --disable-shared --disable-tga --disable-expat --disable-libxml --disable-tinyxml --disable-samples PKG_CONFIG_PATH="/home/fero/code/P3/pcre-8.10/lib/pkgconfig" LDFLAGS="-L/home/fero/code/P3/pcre-8.10/lib -L/home/fero/code/P3/FreeImage/lib -L/home/fero/code/P3/wxWidgets-2.8.11/lib" CPPFLAGS="-I/home/fero/code/P3/pcre-8.10/include -I/home/fero/code/P3/FreeImage/include -I/home/fero/code/P3/wxWidgets-2.8.11/include -DCEGUI_STATIC -DCEGUI_FALAGARD_RENDERER -DCEGUI_WITH_XERCES -DCEGUI_CODEC_FREEIMAGE"

As you can see the CEGUI_FALAGARD_RENDERER, CEGUI_WITH_XERCES, and CEGUI_CODEC_FREEIMAGE defines were added on top of the required CEGUI_STATIC define and passed into the LDFLAGS for CEGUI's configure to force the inclusion of those module's header files based on the #ifdef statements in cegui/src/CEGUISystem.cpp file (e.g. #include "XMLParserModules/XercesParser/CEGUIXercesParserModule.h)

This generates the following static libraries:
    libCEGUIBase.a
    libCEGUIFalagardWRBase.a
    libCEGUIFreeImageImageCodec.a
    libCEGUIOpenGLRenderer.a
    libCEGUIXercesParser.a

    NOTE: The required libraries (FreeImage v3.13.1, PCRE v8.10, and wxWidgets v2.8.11) for building CEGUI in this configuration were also built statically

Running strings and nm on libCEGUIFalagardWRBase.a, libCEGUIFreeImageImageCodec.a, and libCEGUIXercesParser.a show that the undefined reference to XXX mentioned in the first code block exist in the static library

Code: Select all

strings libCEGUIFalagardWRBase.a | grep getWindowRendererModule
getWindowRendererModule
getWindowRendererModule
getWindowRendererModule
_ZGVZ23getWindowRendererModuleE3mod
_ZGVZ23getWindowRendererModuleE3mod
_ZZ23getWindowRendererModuleE3mod
getWindowRendererModule

Code: Select all

nm libCEGUIFalagardWRBase.a | grep getWindowRendererModule
000005e8 T getWindowRendererModule
00000000 b _ZGVZ23getWindowRendererModuleE3mod
00000008 b _ZZ23getWindowRendererModuleE3mod

... a similar result exists for createParser, destoryParser, destroyImageCodec, and createImageCodec when checking them against the libararies libCEGUIFreeImageImageCodec.a and libCEGUIXercesParser.a

Here is the linking line of my application:

Code: Select all

g++ -g3 -fno-inline -O0 -I/usr/include -I../../../mysql-connector/include -I../../../boost/include/boost-1_41 -I../../../protobuf/include -I../../../rapidxml -DLINUX -DDEBUG -g3 -fno-inline -O0 -I/usr/include/GL -I/home/fero/glstudio/include -I/home/fero/glstudio/plugins/include -I/usr/include/mysql -I/home/fero/glstudio/include -I/home/fero/glstudio/plugins/include -I../../../CEGUI-0.7.1/include/CEGUI -I/home/fero/code/P3/pcre-8.10/include -I/home/fero/code/P3/FreeImage/include -I/home/fero/code/P3/wxWidgets-2.8.11/include -DCEGUI_STATIC -DCEGUI_FALAGARD_RENDERER -DCEGUI_WITH_XERCES -DCEGUI_CODEC_FREEIMAGE -I../components/source/ -I../../common -I../../common/data -I../../common/components/source -I../../common/disti -I../../common/logic -I../../common/events/source -DCPPCONN_PUBLIC_FUNC= -DIOS_APPLICATION -DWITH_MILLISECONDS -o ios CEGUIManager.o IOSApplication.o IOSConsoleApp.o CEGUIPanel.o BaseApplication.o ConversionUtils.o Location.o MySQLConnection.o Orientation.o PACT3Event.o StationGLSBase.o TimerInterface.o DCIPanel.o _DCIKnobPopup.o DatabaseObject.o DCIICSData.o DCIModeData.o DCIMonData.o DCITrData.o DCIUSRData.o DigitalCrewInterfaceData.o StartupScenarioParametersData.o Highlightable.o HighlightGlsSwitch.o HighlightGlsKnob.o Testable.o event.pb.o DCIICSLogic.o DCILogic.o DCIMonLogic.o DCITrLogic.o DCIUSRLogic.o LogicBase.o SubLogicBase.o DCILogicMySQLConnection.o  -L/home/fero/code/P3/mysql-connector/driver -L/home/fero/code/P3/boost/lib -L/home/fero/code/P3/protobuf/lib -L/usr/X11R6/lib -L/home/fero/glstudio/lib -L/home/fero/glstudio/plugins/lib -L/usr/lib/mysql -lmysqlcppconn-static -lboost_date_time-gcc34-mt-sd -lboost_filesystem-gcc34-mt-sd -lboost_program_options-gcc34-mt-sd -lboost_serialization-gcc34-mt-sd -lboost_system-gcc34-mt-sd -lboost_thread-gcc34-mt-sd /home/fero/code/P3/protobuf/lib/libprotobuf.a -lglsutil_Linux_gcc_342 -lgls_unlimited_Linux_gcc_342 -lglstudioLinux_gcc_342 -L/home/fero/code/P3/CEGUI-0.7.1/lib -L/home/fero/code/P3/pcre-8.10/lib -L/home/fero/code/P3/FreeImage/lib -L/home/fero/code/P3/wxWidgets-2.8.11/lib -lgls_text_grid_Linux_gcc_342 -lgls_moving_eye_Linux_gcc_342 -lgls_multi_view_Linux_gcc_342 -lgls_thumb_wheel_Linux_gcc_342 -lgls_odometer_Linux_gcc_342 /usr/lib/mysql/libmysqlclient.a -lpthread -lcrypt -lnsl -lm /home/fero/code/P3/CEGUI-0.7.1/lib/libCEGUIFreeImageImageCodec.a -lfreeimage /home/fero/code/P3/CEGUI-0.7.1/lib/libCEGUIXercesParser.a -lxerces-c /home/fero/code/P3/CEGUI-0.7.1/lib/libCEGUIFalagardWRBase.a /home/fero/code/P3/CEGUI-0.7.1/lib/libCEGUIOpenGLRenderer.a /home/fero/code/P3/CEGUI-0.7.1/lib/libCEGUIBase.a /usr/lib/libfreetype.so /usr/lib/mysql/libz.a /home/fero/code/P3/pcre-8.10/lib/libpcre.a -lglut -lGLU /usr/lib/libGL.so -lXext -lX11 -ldl -lSM -lICE

I show this only to indicate that the libraries and the library locations exist during the link step, which based on strings and nm make the undefined references that much more confusing.

I have also tried the same configure and build process using the latest version of CEGUI in subversion (r2577) and the same undefined references exist there too. This only seems to be an issue when trying to statically link my application with CEGUI and does not exist when CEGUI is configured to create shared objects for runtime loading.

Some other information that might be useful:
    RedHat Enterprise Linux 4
    g++ version is 3.4.6
    32-bit architecture

Any information or suggestions would be greatly appreciated!
~Fero

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

Re: Issue with Static Linking of CEGUI v0.7.1 - Linux

Postby CrazyEddie » Fri Aug 06, 2010 08:49

I think it has to do with the order the libraries are specified, you need to ensure that libs appear before any other libs that they depend on (so mainly in this case, that CEGUIBase.a appears before the image codec and xml parser libs).

It will probably interest you to know that while static libs were not officially supported in 0.7.1, they will be in the next release - so you'll be able to just say '--enable-static --disable-shared' and not have to worry about the additional defines and such :)

HTH

CE.

User avatar
fero
Just popping in
Just popping in
Posts: 5
Joined: Thu Aug 05, 2010 19:22
Location: Orlando, FL

Re: Issue with Static Linking of CEGUI v0.7.1 - Linux

Postby fero » Fri Aug 06, 2010 11:40

CrazyEddie wrote:I think it has to do with the order the libraries are specified, you need to ensure that libs appear before any other libs that they depend on (so mainly in this case, that CEGUIBase.a appears before the image codec and xml parser libs).

Thanks for the quick reply CE ... I assumed the order was the issue as well, but moving them around to be in dependency order (CEGUIFreeImageImageCodec.a CEGUIXercesParser.a CEGUIFalagardWRBase.a CEGUIOpenGLRenderer.a CEGUIBase.a) didn't fix the issue either. I had also assumed that that maybe the extern "C" in the 3 modules for the 5 method definitions that are coming up as undefined references was the issue, but strings and nm proved that to not be the case as the methods were not being mangled with g++ compilation.

CrazyEddie wrote:It will probably interest you to know that while static libs were not officially supported in 0.7.1, they will be in the next release - so you'll be able to just say '--enable-static --disable-shared' and not have to worry about the additional defines and such :)

That will be nice to see in future releases!
~Fero

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

Re: Issue with Static Linking of CEGUI v0.7.1 - Linux

Postby CrazyEddie » Fri Aug 06, 2010 13:36

I think the order should be largely reversed:
CEGUIOpenGLRenderer.a CEGUIBase.a CEGUIFreeImageImageCodec.a CEGUIXercesParser.a CEGUIFalagardWRBase.a

Basically, CEGUIBase contains references to those functions, so the libs containing them must appear afterwards. If it still does not work, I'll have to run a test myself :)

CE.

User avatar
fero
Just popping in
Just popping in
Posts: 5
Joined: Thu Aug 05, 2010 19:22
Location: Orlando, FL

Re: Issue with Static Linking of CEGUI v0.7.1 - Linux

Postby fero » Fri Aug 06, 2010 14:37

Still a no go ... The odd thing is this is not an issue when building CEGUI with the shared objects and dynamically loading the modules.
~Fero

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

Re: Issue with Static Linking of CEGUI v0.7.1 - Linux

Postby CrazyEddie » Sat Aug 07, 2010 13:36

Ok, thanks for the information. I'll run a test of my own with the 0.7.1 code, a configure line based on yours, and see if i can reproduce the results :)

CE.

User avatar
fero
Just popping in
Just popping in
Posts: 5
Joined: Thu Aug 05, 2010 19:22
Location: Orlando, FL

Re: Issue with Static Linking of CEGUI v0.7.1 - Linux

Postby fero » Thu Sep 02, 2010 13:38

CE,

I noticed that the new v0.7.2 has been released and saw the following bug fix:

Code: Select all

- Bug Fix: static build / linking was not working correctly for autotools based builds.


I decided to revert back to a static build and test with the latest release ... same issues still exist. I am not sure if you have had any time to attempt to reproduce the results, but I figured I would check back in and see if you had any other thoughts.
~Fero

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

Re: Issue with Static Linking of CEGUI v0.7.1 - Linux

Postby CrazyEddie » Sun Sep 05, 2010 08:34

Ok, first an apology, since it appears that I never did test things specifically for your issue :oops: I'm adding a ticket to mantis this morning so that this will not get forgotten again.

However, I did test somewhat when I made fixes that resulted in that change log entry, and static linking was working - at least at that point :lol:

I'll report back soon. If you don't hear anything in a week to 10 days, bump this to remind me :P

CE.

DEvil HUnter
Just popping in
Just popping in
Posts: 7
Joined: Thu Sep 09, 2010 13:37

Re: Issue with Static Linking of CEGUI v0.7.1 - Linux

Postby DEvil HUnter » Thu Sep 09, 2010 14:14

hi there,
i have the same problem but using ms vs2010. (still using cegui 0.71)
if i link it as dll all workes fine.
if i link it as lib it gets linked - fine on the first look (warning lnk4221). but if i link my program using it i get link errors: (LNK2001), LNK2019.
for example (of course depending on what funktion i use at what point of code):

Code: Select all

6>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class CEGUI::String const & __thiscall CEGUI::Exception::getMessage(void)const " (__imp_?getMessage@Exception@CEGUI@@QBEABVString@2@XZ) referenced in function __catch$_WinMain@16$0


i analysed the symbols in the libs for dll and static linking.
the method getMessage was realy missing in the static linked one.
after that i analysed the exceptions.obj file - again missing method if i link statically (but method

Code: Select all

const char* Exception::what() const throw()
was in it)

so i watched the code and now i have found the problem!
the functions not linking in static are written like this:

Code: Select all

const String& getMessage(void) const
        { return d_message; }

i think the compiler treats them for inline (even when inline is strictly forbidden) or just don't use it because nobody is using it or what ever.
solution: put method body in the cpp file -> after that this function seams to work also statically linked...

i'm not sure if it's a error in compiler/linker or defined that way in the standartisation.
but it's strange that it is working with dynamically linked.

hope you will release a fix soon - i don't want to change all that functions on my own^^

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

Re: Issue with Static Linking of CEGUI v0.7.1 - Linux

Postby CrazyEddie » Thu Sep 09, 2010 18:24

I don't think you have the same issue, since the static build on Win32 gets tested a lot more (not only by me, but by others using it every day).

Your error message here:

Code: Select all

    6>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class CEGUI::String const & __thiscall CEGUI::Exception::getMessage(void)const " (__imp_?getMessage@Exception@CEGUI@@QBEABVString@2@XZ) referenced in function __catch$_WinMain@16$0


Tells me that you're compiling your app without CEGUI_STATIC defined. For static linking, you must define CEGUI_STATIC for all files and components that will be linked - the best place to do this is in the preprocessor macros for your MSVC++ projects.

HTH

CE

PS. Note to OP. I will be testing the linux issue, definitely, 100% guaranteed - tomorrow! And I'll report back then.

DEvil HUnter
Just popping in
Just popping in
Posts: 7
Joined: Thu Sep 09, 2010 13:37

Re: Issue with Static Linking of CEGUI v0.7.1 - Linux

Postby DEvil HUnter » Fri Sep 10, 2010 05:43

hi,
ok maybe it's a different problem and maybe it's only at my side.
i thougth it's maybe the same because of the error type and the functions we call.

i was running premake to set up the projects for vs2008 and than opening it with vs2010 so the project gets updated to vs2010.
in the project are compiling configurations one of them for compiling as "debug_static".

i checked the define twice! it is there and workes correct!

i also tryed with vs2008 compiler/linker/libs (inside of vs2010 you can change this on the projects general options page).
i got the same problem.

it seams like the main parts of the lib are linked correct. and using the "debug" configuration all of it is linking correct - and my app is working.
just with static linking it seams to make a difference only with methods that have the body direct in the header and not in the cpp file!
(yes i made a config for static linked libs in my app - and it realy should be configured right way and should work as far as i can see.)
i changed localy the described method in the source to have the body in the cpp - after that this error was gone and the method was in the object file and in the lib (analysed as i said).
so i realy don't think it's kind of a config problem or something like that.

edit:
maybe it's a new problem with vs2010.
maybe because of the changes with C++0x in vs2010.
maybe only with newer compiler/linker generations of vs versions.
maybe something else.

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

Re: Issue with Static Linking of CEGUI v0.7.1 - Linux

Postby CrazyEddie » Fri Sep 10, 2010 12:32

@fero:
I today got around to testing static support in 0.7.2. This was tested using a set up as far removed from the regular CEGUI samples set up as I could get, in order that nothing 'special' got picked up from there. My CEGUI for the test was built with the following configure line:

Code: Select all

$ ../configure --enable-static --disable-shared --disable-tga --disable-expat --disable-libxml --disable-tinyxml --disable-samples --disable-devil --disable-silly --disable-ogre-renderer --disable-irrlicht-renderer --disable-lua-module --prefix=/home/paul/dev/cegui/CEGUI_STATIC

And subsequently the files were installed to the location mentioned above.

I made a test app, which basically sets up an X11 window with GL context, and started up the CEGUI system and created a test CEGUI window (i.e. the code from the tutorials).

I built my test app with the following command:

Code: Select all

g++ main.cpp -o test -DCEGUI_STATIC -I/home/paul/dev/cegui/CEGUI_STATIC/include/CEGUI -L/home/paul/dev/cegui/CEGUI_STATIC/lib/ -lCEGUIOpenGLRenderer -lCEGUIBase -lCEGUIFalagardWRBase -lCEGUIFreeImageImageCodec -lCEGUIXercesParser -lfreetype -lpcre -lxerces-c -lfreeimage -lX11 -lGL -lGLU -lGLEW


My test app builds and runs successfully :? The only, maybe major, difference I see is that I use gcc 4.4.3, though to be honest I wouldn't have thought a compiler issue would have caused issues at this point, and doing something so basic as linking. It seems your own configure and build lines contain a bunch of defines and such that mine do not, so I would begin by trying to get as close to the above as you can.


@DEvil HUnter:
I tested the static build on MSVC++ 2010 via the samples that come with the SDK for the same, though I was careful to ensure I modified the code I built to reference the specific symbol that you've reported issues with. Aside from a minor glitch in the freeglut lib in the dependencies (related to the fact I forgot to remove the idiotic use of #pragma to link libs), there were no issues, and definitely no unresolved symbols at link time.

I will reiterate my reply from earlier. The fact that the error mentions '__declspec(dllimport)' means that the symbol / class has that attribute specified for it. As we clearly can see here (from CEGUIBase.h):

Code: Select all

#if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC)
#   ifdef CEGUIBASE_EXPORTS
#       define CEGUIEXPORT __declspec(dllexport)
#   else
#       define CEGUIEXPORT __declspec(dllimport)
#   endif
#       define CEGUIPRIVATE
#else
#       define CEGUIEXPORT
#       define CEGUIPRIVATE
#endif

When CEGUI_STATIC is defined, that attribute is not - indeeed, can not - be associated with the CEGUIEXPORT macro which controls how symbols are imported or exported from DLLs.

I was unable to tell from your post whether you checked the CEGUI library projects or your own app's project for the macro. Obviously it exists in the static builds for the CEGUI library projects, it's your own project that needs to define the macro, so if you did not already check that (as I say, it was not clear from your post precisely what you checked).

CE.

DEvil HUnter
Just popping in
Just popping in
Posts: 7
Joined: Thu Sep 09, 2010 13:37

Re: Issue with Static Linking of CEGUI v0.7.1 - Linux

Postby DEvil HUnter » Fri Sep 10, 2010 18:09

hi,
i apologise. i missed to add the precompiler define in one sub projekt (my error handler). thougth main project would be enought
now it seams to working.

btw why do i need to add some libs in main project for silly image and stuff?
is it still using silly as dll - even if i build cegui stuff with static?

much thanks and again - apologise

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

Re: Issue with Static Linking of CEGUI v0.7.1 - Linux

Postby CrazyEddie » Mon Sep 13, 2010 08:43

DEvil HUnter wrote:btw why do i need to add some libs in main project for silly image and stuff?
is it still using silly as dll - even if i build cegui stuff with static?

There are two versions of the dependencies (which I'll cover in your other post ;)), but when using the 'static' versions of the dependency libraries, no you will not be using the SILLY.dll or indeed any other DLL.

If you don't know why you need to link the final .exe in your project with all the dependent libraries for a static build, then you should do some research on exactly what static linking is and how - and why - it differs from dynamic linking. Basically, though, a static library is just an archive of compiled .o or .obj files, and generally speaking you do not / can not link other libraries to a static library (which is why there's normally no 'linker' settings in MSVC++ for static libs). This means that when you eventually link your final .exe you need to make sure that all referenced symbols are available for resolution by the linker - and that means you need to link to all libs and their dependent libs right the way down.

CE.

User avatar
fero
Just popping in
Just popping in
Posts: 5
Joined: Thu Aug 05, 2010 19:22
Location: Orlando, FL

Re: Issue with Static Linking of CEGUI v0.7.1 - Linux

Postby fero » Mon Sep 13, 2010 15:59

CE,

Thanks for looking into this. I will experiment some more in the next couple weeks to try and narrow down what is causing the problem (autotools, gcc, ld, ...etc). Once (if) I come up with a solution to my problems I will post that information here.
~Fero


Return to “Help”

Who is online

Users browsing this forum: No registered users and 10 guests