So I try to port some Boost.Extension samples for linux.
The sample is described here. Here is my code port (classes with animals, animal prototype, main app, general all port idea is described here, and some current linux progress here (some samples really work as needed!)). When I compile this sample under linux it compiles, it finds library with animals but outputs:
Animals not found!
Which shall happen only if(factories.empty())
.
I try to port Extension samples onto crossplatform base - so I have tried same code under windows - works like a charm! finds all animals and outputs:
Creating an animal using factory:
Cougar factory Created an animal:
cougar Age: 2 Creating an animal using
factory: Leopard factory Created an
animal: leopard Age: 3 Creating an
animal using factory: Puma factory
Created an animal: puma Age: 4
Creating an animal using factory:
Wildcat factory Created an animal:
wildcat Age: 5
So... Why it behaves so on linux with same code? Why it works so well under Windows?
Update:
So how to build this stuff with premake:
- You get svn from here (only this folder is required)
- You get premake for your platform or build it from source and put it into folder you downloaded from svn
- You should have official Boost compiled and installed (please read ReadMe.txt file we provide in directory) so what is needed:
- Boost C++ library's (we tested with version 1.4.16)
- Boost-Extension ( we use latest revision , we adress it as part of boost 'boost/extension/
**
' We had to make some chandes (actually only one) to boost extension so we provide it insideBoost.Extension.Tutorial/libs/boost/extension/
folder so when you downloaded svn you got it, it is header only ) - Boost-Reflection ( we use it because of this tutorial , we use latest revision , we adress it as part of boost 'boost/reflection/
**
' *and for simplness we recommend just to put it intoBoost.Extension.Tutorial/libs/boost/reflection
* )
- Now when official Boost is in your system, header only Boost-reflection and Boost-extension are in
Boost.Extension.Tutorial/libs/boost
folder, premake4 executable is insideBoost.Extension.Tutorial/
folder we can simply callBoost.Extension.Tutorial/ premake4-build-windows.bat
on windows to get sln for Visual Studio orBoost.Extension.Tutorial/ premake-build.sh
to get makefiles. - You can find generated solution/makefiles inside generated projects folder.
- Have good luck!=)
Update 2:
Project files for Windows and Linux are now in svn so you can get aroung project creation with premake - just have Boost, our svn, and reflection headers only lib.
I debugged things on linux, good news:
You are running into bullet no. 3 from Jeremy Pack's post:
I have a tiny workaround patch (below) to
boost/extension/impl/typeinfo.hpp
(but you need to talk to the maintainer of Boost Extension, really). What this does is not rely on builtin comparison for RTTI typeinfo's.Looking at typeinfo.hpp, it seems that Windows never actually uses the typeinfo comparison, so I decided to test with the 'strcmp' fallback method, and voila:
In particular, I can show that the type lookup from
convertible_
fails at type_map.hpp, line 68;.
Patch
GCC on Linux by default has stricter linker optimization settings that MSVC on Windows. This leads to some factory patterns where classes register themselves as available appearing broken, simply because the linker optimizes away the classes. I didn't look at your code - but from the description it could be the problem.
A related question, with an answer on how to avoid the unreferenced classes being dropped: How to force gcc to link unreferenced, static C++ objects from a library