Rel*_*lla 2 c++ linux boost boost-extension
所以我尝试为Linux移植一些Boost.Extension示例.
这里描述了样本.这是我的代码端口(类动物,动物原型,主应用程序,一般所有端口的想法在这里描述,以及一些当前的Linux进展(一些样本真的按需工作!)).当我在linux下编译这个样本时,它会编译,它会找到带有动物的库,但输出:
Animals not found!
Run Code Online (Sandbox Code Playgroud)
这只会发生if(factories.empty()).
我尝试将扩展示例移植到跨平台基础上 - 所以我在windows下尝试了相同的代码 - 就像一个魅力!找到所有动物和输出:
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
Run Code Online (Sandbox Code Playgroud)
那么......为什么它在linux上使用相同的代码呢?为什么它在Windows下运行良好?
更新:
那么如何使用premake构建这些东西:
**'的一部分进行调整我们必须制作一些chandes(实际上只有一个)来提升扩展名,所以我们在Boost.Extension.Tutorial/libs/boost/extension/文件夹中提供它,所以当你下载svn时你得到了它,它只是标题)**' *的一部分进行处理,为简单起见,我们建议将其放入Boost.Extension.Tutorial/libs/boost/reflection*)Boost.Extension.Tutorial/libs/boost文件夹中,premake4可执行文件在Boost.Extension.Tutorial/文件夹内,我们可以简单地调用Boost.Extension.Tutorial/ premake4-build-windows.batwindows来获取sln for Visual Studio或 Boost.Extension.Tutorial/ premake-build.sh获取makefile.更新2:
Windows和Linux的项目文件现在都在svn中,所以你可以通过premake来创建项目 - 只需要Boost,我们的svn和反射头只有lib.
我在linux上调试了一些东西,好消息:
你正在遇到子弹没有.3来自Jeremy Pack的帖子:
RTTI并不总是在DLL边界上按预期运行.查看type_info类以了解我如何处理它.
我有一个小的解决方法补丁(下面)boost/extension/impl/typeinfo.hpp(但你需要与Boost扩展的维护者交谈,真的).这样做不依赖于RTTI typeinfo的内置比较.
看看typeinfo.hpp,似乎Windows从未真正使用过typeinfo比较,所以我决定使用'strcmp'回退方法进行测试,并且瞧:
$ 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
Run Code Online (Sandbox Code Playgroud)
特别是,我可以convertible_在type_map.hpp第68行显示类型查找失败;
.
73 if (it == instances_.end()) {
74 holder = new type_holder<StoredType>;
75 it = instances_.insert(std::make_pair(t, holder)).first;
76 }
Run Code Online (Sandbox Code Playgroud)
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) {
Run Code Online (Sandbox Code Playgroud)