标签: stlport

如何将boost库(包括shared_ptr)与Android NDK和STLport一起使用

这更像是一个答案,而不是一个问题,因为我已经弄明白了,至少就干净地编译图书馆而言.对我来说,主要问题是让shared_ptr工作.

配料:

Boost v.1.45.0

STLport的版本位于http://www.anddev.org/viewtopic.php?p=29939.

NDK的版本r4b.

路线:

在你的Android.mk文件中添加:

LOCAL_CFLAGS += -DBOOST_EXCEPTION_DISABLE -D_STLP_NO_EXCEPTIONS -DOS_ANDROID -D_STLP_USE_SIMPLE_NODE_ALLOC
Run Code Online (Sandbox Code Playgroud)

在stlport/stl/_string.h的第613行删除对__stl_throw_length_error的调用.如果您愿意,可以使用_STLP_NO_EXCEPTIONS.

在第261行之后编辑boost/boost/smart_ptr/shared_ptr.hpp以消除对shared_ptr构造函数中对boost :: throw_exception的调用.我在方法的整个主体周围使用了#ifndef BOOST_EXCEPTION_DISABLE.(但请参阅下面的答案.)

接下来你需要提供一些缺失的部分.使用以下内容创建头文件:

#ifdef OS_ANDROID

#include <exception>

namespace std
{
    struct bad_alloc : public exception { bad_alloc operator()(){}};
}

#endif
Run Code Online (Sandbox Code Playgroud)

和一个带有精简异常类的源文件,以支持bad_alloc:

#ifdef OS_ANDROID

#include <exception>

namespace std
{
    exception::exception() {}
    exception::~exception() {}
    const char* exception::what() const {}
}

#endif
Run Code Online (Sandbox Code Playgroud)

在包含boost/shared_ptr.hpp的任何地方都包含标题.编译源代码并将其添加到库中.

c++ boost stlport android-ndk

57
推荐指数
1
解决办法
2万
查看次数

如何在我自己的容器类中使用std :: allocator

我正在尝试编写一个使用STL分配器的容器类.我目前所做的是拥有一名私人会员

std::allocator<T> alloc_;
Run Code Online (Sandbox Code Playgroud)

(稍后将模板化以便用户可以选择不同的分配器)然后调用

T* ptr = alloc_.allocate(1,0);
Run Code Online (Sandbox Code Playgroud)

获取指向新分配的'T'对象的指针(并使用alloc_.construct来调用构造函数;请参阅下面的答案).这适用于GNU C++库.

但是,对于Solaris上的STLPort,这无法做正确的事情并导致各种奇怪的内存损坏错误.如果我改为做

std::allocator_interface<std::allocator<T> > alloc_;
Run Code Online (Sandbox Code Playgroud)

然后一切正常.

使用stl :: allocator的正确方法是什么?STLPort/Solaris版本无法使用g ++进行编译,但是g ++是正确的吗?

c++ memory-management g++ stlport

20
推荐指数
2
解决办法
7816
查看次数

获取错误:名称空间"std"中的"shared_ptr"未命名类型

我试图在android studio(ndk r10d)中编译一个使用一些C++代码的android应用程序.我需要C++ 11所以我添加-std=gnu++11(我需要gnu++11而不是c++11我正在使用的扩展).我正在使用stlport stl,因为我正在使用的其他库使用这个stl库.所以我在build.gradle文件中的cFlags和stl参数如下所示:

stl "stlport_static"
cFlags " mylib1.a mylib2.a ... -fexceptions -frtti -std=gnu++11"
Run Code Online (Sandbox Code Playgroud)

我也包含了内存: #include <memory>

在尝试编译时,我收到此错误:

'shared_ptr' in namespace 'std' does not name a type
Run Code Online (Sandbox Code Playgroud)

到目前为止,我一直在使用智能指针的boost实现,但随着转向c ++ 11,我宁愿使用标准实现.

android stlport c++11 android-studio

16
推荐指数
2
解决办法
3万
查看次数

支持C++ 11的开源STL实现

简而言之,我正在寻找STLPort的替代品.STLPort有一段时间没有更新(自2008年以来?),并且缺乏C++ 11支持.有谁知道任何替代品?我需要使用各种工具链进行编译,适用于各种体系结构和各种目标操作系统.

我将开始研究GNU C++实现,看看它与GCC工具链的关系如何作为替代,并将回发结果.但如果有人在这里有任何前期知识,那将是伟大的.

替代方案是实现各种关键的C++ 11 STL功能,如新的智能指针类型和std :: threads.最糟糕的情况我可以从boost中提取智能指针.就pthreads或Windows线程而言,是否存在std :: threads的任何实现?

谢谢

c++ stl stlport c++11

14
推荐指数
1
解决办法
3785
查看次数

无法使用STLport库构建Boost

我正在使用MSVC 7.1在Windows上使用STLport 5.2.1构建boost 1.48.0,这是我运行的命令行:

b2 toolset=msvc link=shared threading=multi runtime-link=shared variant=debug stdlib=stlport --layout=tagged stage
Run Code Online (Sandbox Code Playgroud)

我的user-config.jam设置如下:

using msvc : 7.1 ;
using stlport : 5.2.1 : C:/Code/third_party_source/STLport-5.2.1/stlport : C:/Code/third_party_source/STLport-5.2.1/lib ;
Run Code Online (Sandbox Code Playgroud)

我收到了几个与STLport相关的链接器错误.其中一个看起来像这样:

path.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall stlpd
_std::basic_string<wchar_t,class stlpd_std::char_traits<wchar_t>,class stlpd_std::allocator<wchar_t>
 >::basic_string<wchar_t,class stlpd_std::char_traits<wchar_t>,class stlpd_std::allocator<wchar_t> >
(class stlpd_std::basic_string<wchar_t,class stlpd_std::char_traits<wchar_t>,class stlpd_std::alloca
tor<wchar_t> > const &)" (__imp_??0?$basic_string@_WV?$char_traits@_W@stlpd_std@@V?$allocator@_W@2@@
stlpd_std@@QAE@ABV01@@Z)
Run Code Online (Sandbox Code Playgroud)

为什么我不能使用STLport构建Boost?

boost build stlport

7
推荐指数
1
解决办法
2595
查看次数

std :: string insert方法有多么模糊的重载?

环境:使用STLPort 5.1.4的VS2005 C++.

编译以下代码段:

std::string copied = "asdf";
char ch = 's';
copied.insert(0,1,ch);
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

Error   1   error C2668: 'stlpx_std::basic_string<_CharT,_Traits,_Alloc>::insert' : ambiguous call to overloaded function   
Run Code Online (Sandbox Code Playgroud)

似乎问题是对字符串对象的insert方法调用.

两个定义的重载是

void insert ( iterator p, size_t n, char c );
string& insert ( size_t pos1, size_t n, char c );
Run Code Online (Sandbox Code Playgroud)

但是鉴于STLPort使用一个简单的char*作为迭代器,我的代码中insert方法中的文字零是不明确的.

因此,虽然我可以通过暗示如此轻松地克服这个问题

copied.insert(size_t(0),1,ch);
Run Code Online (Sandbox Code Playgroud)

我的问题是:规范中是否存在这种过载和可能模糊的问题?或者更有可能是特定STLPort实现的意外副作用?

(请注意,Microsoft提供的STL没有此问题,因为它有一个迭代器类,而不是裸指针)

c++ stl stlport

5
推荐指数
1
解决办法
1385
查看次数

Android NDK中缺少std :: wstring支持的解决方案?

我有一个游戏,它使用std :: wstring作为其基本字符串类型在数千个地方以及使用wchar_t及其函数进行操作:wcsicmp()wcslen()vsprintf()等.

问题是R5c不支持wstring(此写入时最新的ndk).

我无法改变代码使用std :: string因为国际化而且我会破坏许多游戏使用的游戏引擎......

我有哪些选择?

1 - 用我自己的字符串类替换字符串和wstring

这将使我更好的平台独立性,但它是荒谬重新实现车轮.我已经开始使用字符串的COW实现了.我需要它是COW,因为我将它们用作hash_maps中的键.这当然是很多工作和容易出错......但似乎这是我能做的事情.

2 - 尝试使用我自己的C标准库(wcslen,mbstowcs ...)的宽字符串函数实现来修复NDK重新编译STLPort

这将是更好的方式......但我不知道该怎么做:(

如何在libstdc ++.a或libstlport_static.a中替换函数(比如说wcslen)?(不确定它们在哪里:()

而且我不确定我需要重新实现哪些功能,我知道wcslen没有工作所以我猜他们应该全部......

3 - 你还有其他想法吗?

我不能等待正式的修复,如果我不知道如何做#2,我将不得不选择#1选项.

我已经读到某个地方,如果你的目标是2.3你可以使用wstrings,但我应该定位Android 2.1.

PS:忘了说我当然需要使用STL,但没有RTTI,我可以无异常地生活.

提前致谢!

wchar-t stlport wstring android-ndk

5
推荐指数
1
解决办法
4861
查看次数

编译引用STLport-5.1.4和VC++ 2008的应用程序时出现LNK2001错误

我为这篇长篇文章提前道歉...

当我们在VS菜单>工具>选项> VC++目录>包含和包含文件的目录下列出STLPort包含和库目录时,我曾经能够构建我们的VC++解决方案(我们在VS 2008上).但是,我们希望转换到完全依赖.vcproj和.sln文件的构建过程.与VS选项不同,这些可以检查到源控制中,VS选项必须分别在每台开发PC上配置.我们通过将Include目录添加到每个项目的属性页>配置属性> C/C++>常规>其他包含目录和库目录到链接器>常规>其他库目录来处理大多数库的转换.

不幸的是,这种方法不适用于STLPort.我们在链接期间收到LNK2019和LNK2001错误:

Error   1   error LNK2019: unresolved external symbol "public: virtual bool __thiscall MyClass::myFunction(class stlp_std::basic_istream<char,class stlp_std::char_traits<char> > &,class MyOtherClass &,class stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> > &)const " (?myFunction@MyClass@@UBE_NAAV?$basic_istream@DV?$char_traits@D@stlp_std@@@stlp_std@@AAVSbprobScenarioData@@AAV?$basic_string@DV?$char_traits@D@stlp_std@@V?$allocator@D@2@@3@@Z) referenced in function _main MyLibrary.obj   

Error   5   error LNK2001: unresolved external symbol "public: static void __cdecl MyClass::myFunction(class stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> > const &,class stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> > const &,class stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> > const &,class stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> > const &,long,enum MyClass::MessageType,int,class stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> > const &)" (?myFunction@MyClass@@SAXABV?$basic_string@DV?$char_traits@D@stlp_std@@V?$allocator@D@2@@stlp_std@@000JW4MessageType@1@H0@Z) …
Run Code Online (Sandbox Code Playgroud)

c++ linker stlport visual-studio-2008 visual-c++

2
推荐指数
1
解决办法
2993
查看次数

2
推荐指数
1
解决办法
331
查看次数

STL vs Stlport:哪一个更轻量级

我正在使用stlport开发基于wince的自定义操作系统,但从现在开始我正在考虑使用windows提供的stl.我从功能上读到它们并没有什么不同,所以目前重要的是我的图像大小.不幸的是,我不能给他们两个尝试像第一次使用stl并制作运行时图像然后使用stlport,然后比较两个图像的大小,因为我有很多其他问题,我需要解决,以便成功构建OS.因此我想得到一个专家的想法:

您认为哪一个更轻巧?我知道如何附加,加载等stlport但我不太确定STL.我查看了STL标题,我看到的只有成千上万的内联函数.但这就是全部吗?我需要确定一下.STL是否链接了任何其他库,或者只是包含标题并使用这些内联函数?

最好

Ps:我正在使用VS2012并在wec2013上工作

Ps2:我知道STL和stlport代表什么以及如何使用它们构建应用程序.我的实际问题是哪一个会占用更少的内存,在HDD上使用更小的内存?(考虑像stlport这样的东西是lib,但stl不是等等)

c++ stl stlport windows-embedded-compact

1
推荐指数
1
解决办法
2344
查看次数

STLPort使用C++ 11

我正在尝试将我的办公室代码从C++迁移到C++ 11,我们大量使用STLPorts.

有一个编译器宏(http://www.stlport.org/doc/configure.html) - _STLP_LONG_LONG,它在我们的代码中使用,在C++中工作正常.

但是,在C++ 11中,没有定义.

#if defined (_STLP_LONG_LONG)
// Doesn't come here
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?我尝试在互联网上搜索,但资源非常有限.

编辑:这是代码

# if defined (_STLP_MSVC) || defined (__BORLANDC__) || defined (__ICL)
# define ULL(x) x##Ui64
typedef unsigned _STLP_LONG_LONG uint64;
# elif defined (_STLP_LONG_LONG) /// <---- Here
typedef unsigned _STLP_LONG_LONG uint64;
# define ULL(x) x##ULL
# elif defined(__MRC__) || defined(__SC__)              //*TY 02/25/2000 - added support for MPW compilers
# include "uint64.h"            //*TY 03/25/2000 - added 64bit math type definition
# else
#  error "there …
Run Code Online (Sandbox Code Playgroud)

c++ stlport c++11

0
推荐指数
1
解决办法
141
查看次数