本文介绍了Boost.Extension - 简单的继承样本 - 为什么我们看到在Linux上没有动物?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我一些Boost.Extension样本。

So I try to port some Boost.Extension samples for linux.

样品描述此处。这里是我的code口(<一个href=\"http://$c$c.google.com/p/cloudobserver/source/browse/branches/v0.4/Boost.Extension.Tutorial/src/lib-simple-inheritance/animals.cpp?r=1109\"相对=nofollow>与动物类,<一个href=\"http://$c$c.google.com/p/cloudobserver/source/browse/branches/v0.4/Boost.Extension.Tutorial/src/headers-interfaces/animal.h?r=1109\"相对=nofollow>动物原型,<一个href=\"http://$c$c.google.com/p/cloudobserver/source/browse/branches/v0.4/Boost.Extension.Tutorial/src/simple-inheritance_main.cpp?r=1109\"相对=nofollow>主要应用,一般描述,并且)。当我在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!

这只能发生如果(factories.empty())

我尝试端口扩展到样品跨平台的基础 - 在Windows下,所以我已经试过同一code - 就像一个魅力!找到所有的动物和输出:

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

所以...为什么它的行为等方面与同code Linux呢?为什么工作这么好,在Windows下?

So... Why it behaves so on linux with same code? Why it works so well under Windows?

更新:

Update:

因此​​,如何建立这个东西用premake:

So how to build this stuff with premake:


  1. 您获得

  2. 您构建它,并把它进入文件夹从SVN下载

  3. 您应该有正式的升压编译和安装(请阅读ReadMe.txt文件,我们在目录中提供),所以需要什么:

    • (用1.4.16版本测试)

    • (我们使用的,我们ADRESS它作为提升的一部分升压/推广/ ** 我们不得不做出一些chandes(其实只有一个),以提高扩展,使我们为他提供 Boost.Extension.Tutorial /库/升压内/推广/ 文件夹,以便当您下载SVN你得到了它,它是唯一的标题

    • 升压反射(我们使用它的,我们使用,我们ADRESS它作为提升的一部分升压/反射/ ** *和simplness我们建议只把它变成 Boost.Extension.Tutorial /库/升压/反射 *

  1. You get svn from here (only this folder is required)
  2. You get premake for your platform or build it from source and put it into folder you downloaded from svn
  3. 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 inside Boost.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 into Boost.Extension.Tutorial/libs/boost/reflection * )

更新2:

Update 2:

Project文件这样你就可以得到aroung项目创建与premake - 只是加速,我们的SVN,和反思头只LIB

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.

推荐答案

我调试Linux上的事情,好消息是:

I debugged things on linux, good news:

您正在运行到:

RTTI并不总是发挥跨边界的DLL预期。退房TYPE_INFO类的,看我怎么面对这一切。

我有一个微小的解决办法修补程序(下同)升压/推广/ IMPL / typeinfo.hpp (但你需要去跟加速扩展的维护者,真的) 。这样做是什么的的依赖于RTTI所属类别的内置比较。

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.

看着typeinfo.hpp,似乎从来没有的Windows实际使用的所属类别比较,所以我决定用'STRCMP回退的方法来测试,瞧:​​

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:

$ LD_LIBRARY_PATH=. ./Simple-Inheritance 
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


在我特别能显示,从类型查找换股_ 失败在type_map.hpp 68行;


In particular, I can show that the type lookup from convertible_ fails at type_map.hpp, line 68;


  • 在当前这种转换是从扩展DLL本身叫,转换高兴地发现使用RTTI比赛。

  • 然而,当'的相同的'获得()从测试应用程序完成的(跨边界的DLL,即)的RTTI是不同的,没有这样的匹配,并线七十五分之七十四被击中:

  • When this conversion is called from the extension dll itself, the conversion happily finds the match using RTTI.
  • However, when the 'same' .get() is done from the test application (across DLL boundaries, i.e.) the RTTI is different and no such match is found, and line 74/75 are hit:
73        if (it == instances_.end()) {
74          holder = new type_holder<StoredType>;
75          it = instances_.insert(std::make_pair(t, holder)).first;
76        }

补丁

diff --git a/Boost.Extension.Tutorial/libs/boost/extension/impl/typeinfo.hpp b/Boost.Extension.Tutorial/libs/boost/extension/impl/typeinfo.hpp
index 843fed2..09fc353 100644
--- a/Boost.Extension.Tutorial/libs/boost/extension/impl/typeinfo.hpp
+++ b/Boost.Extension.Tutorial/libs/boost/extension/impl/typeinfo.hpp
@@ -50,7 +50,7 @@ struct type_info_handler<default_type_info, ClassType>

 // This list should be expanded to all platforms that successfully
 // compare type_info across shared library boundaries.
-#if defined(__APPLE__) || defined(__GNUC__) || \
+#if defined(__APPLE__) || \
     defined(BOOST_EXTENSION_FORCE_FAST_TYPEINFO)
 namespace boost {
 namespace extensions {
@@ -90,7 +90,7 @@ inline bool operator>(const default_type_info& first,
 }  // namespace extensions
 }  // namespace boost
 #else  // OTHER OS
-#include <string>
+#include <cstring>
 namespace boost { namespace extensions {
 inline bool operator<(const default_type_info& first,
                const default_type_info& second) {

这篇关于Boost.Extension - 简单的继承样本 - 为什么我们看到在Linux上没有动物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 04:06