STL for Symbian C++

本文档详细介绍了如何在Symbian C++环境中使用标准模板库(STL)。主要内容包括修改MMP文件以引入所需的库和包含路径,链接libstdcpp库,并设置必要的选项和宏。此外,还提供了一个使用main()作为入口点的简单示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文地址:

http://whyandroid.com/symbian/66-stl-for-symbian-c.html

 

That's all to use STL for Symbian C++

(The section below is copied from the help file of Nokia (The Standard C++ API Reference))

 

Changes to the MMP file

Add needed libraries used by the MMP file structure:

If developers want to use any of the Standard C++ library, they need to link to the corresponding library in the MMP file using the LIBRARY keyword.

If the application has main() as the entry point, the library libcrt0.lib must be specified as the first library otherwise, it will result in linker errors. The user must link to the Symbian OS euser.dll. This is required since the static library uses some of the services of the Symbian OS such as creating cleanup stack, and having a top level TRAP. All these details are hidden from the developer. The developer will write the application as if it were for the UNIX environment.

STATICLIBRARY  libcrt0.lib
LIBRARY        libc.lib 
LIBRARY        euser.lib  // Needed in order to use Symbian services

The libcrt0.lib library is required if we are not going to write E32Main within our application (EXE). This static library has an implementation of E32Main within which it calls the library initialization method followed by calling main written by the developer. This static library also gets command-line arguments and passes the same to main.

 

If the application has E32Main() as an entry point, there is no need to link to libcrt0.lib like in the example below.

LIBRARY         libc.lib 
LIBRARY         euser.lib

Add needed include paths

SYSTEMINCLUDE   /epoc32/include/stdapis
SYSTEMINCLUDE   /epoc32/include/stdapis/sys
SYSTEMINCLUDE   /epoc32/include/stdapis/stlport 

Linking of libstdcpp

The following snippet shows how to perform the linking to libstdcpp on an emulator:

#ifdef EPOC32
LIBRARY  libstdcpp.lib
#else
FIRSTLIB ../udeb/libstdcpp.lib
STATICLIBRARY    eexe.lib 
#endif

Add the below option and macro in the MMP file

//This is required even if the wchar type is not used.
OPTION CW -wchar_t on 
MACRO  _WCHAR_T_DECLARED
NOTE: Standard C++ applications may require more stack space. The recommended stack size is 10K. To set the stack size to 10K add:
EPOCSTACKSIZE 0x10000
in the MMP file.

 

Example using main()

A simple example using main() as an entry point is described below. The example writes a text to a console.
  • Modify the MMP file as mentioned before.
  • Do usual C++ style coding.
//  Include Files  
#include <iostream>
#include <cstring>

// This is a GCCE toolchain workaround needed when compiling with GCCE
// and using main() entry point
#ifdef __GCCE__

#include <staticlibinit_gcce.h>
#endif

using namespace std;

class myclass {
public:
  void show(){cout<<"Hello World/n"; }
} ;

int main()
{
  myclass obj;
  obj.show();
  cout<<"Press a character to exit!";
  int c = getchar();
  return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值