The Standard C++ and Boost Libraries
Developer Guide

Developer Guide

Table of Contents

Getting started with The Standard C++ Library
Changes to the MMP file
Example using main()
Using Open C++ on Carbide
Creating Hello World project
Deleting Hello World Project
Importing Hello World project in Carbide C++
Building Hello World Project
Changing the build configuration

 


Getting started with The Standard C++ Library

The Standard C++ library depends on Open C. The user must have the Open C components installed before using the library.

 


Changes to the MMP file

Add needed libraries used by the MMP file structure:

If developers want to use any of Standard C++ library, they must 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 results 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 for writing to 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 retrieves 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 required include paths

SYSTEMINCLUDE   \epoc32\include\stdapis
SYSTEMINCLUDE   \epoc32\include\stdapis\sys
SYSTEMINCLUDE   \epoc32\include\stdapis\stlport 

Linking of libstdcpp

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;
}

Give feedback on this article

 


Using Open C++ on Carbide

This section provides procedures for using Open C++ on Carbide.

 


Creating Hello World project

  1. File > New and click Project tab to open New Project dialog box

    Figure 1 New Project

  2. Click Next to open New Symbian OS C++ Project dialog box. Select the type of project, for example, Basic console application (EXE).

    Figure 2 New Symbian OS C++ Project

  3. Click Next to open New Basic console application (EXE). Change the default location to a public SDK mapped location with Project name, for example, E:\mobileruntime\HelloWorld

    Figure 3 New Basic console application (EXE)

  4. Click Next and select the particular SDK check box for example, E_S60_5_0_WK_200818.

    Figure 4 SDKs and Build Configurations

  5. Click Finish. Check the C/C++ Projects for the Hello world Project window.

    Figure 5 C/C++ projects

  6. Update Helloworld.mmp with the following details:
    /*
    ============================================================================
     Name		: HelloWorld.mmp
     Author	  : 
     Copyright   : Your copyright notice
     Description : This is the project specification file for HelloWorld.
    ============================================================================
    */
    
    TARGET			HelloWorld.exe
    TARGETTYPE		exe
    UID			0 0xE8212C84
    USERINCLUDE		../inc
    SOURCEPATH		../data
    
    
    SOURCEPATH	  	../src
    SOURCE		  	HelloWorld.cpp
    
    SYSTEMINCLUDE   /epoc32/include
    SYSTEMINCLUDE   /epoc32/include/osextensions/stdapis
    
    SYSTEMINCLUDE   /epoc32/include/stdapis
    SYSTEMINCLUDE   /epoc32/include/osextensions/stdapis/sys
    
    SYSTEMINCLUDE   /epoc32/include/stdapis/sys
    SYSTEMINCLUDE   /epoc32/include/osextensions/stdapis/stlport
    
    SYSTEMINCLUDE    /epoc32/include/stdapis/stlport
    
    
    STATICLIBRARY	libcrt0.lib
    LIBRARY			libstdcpp.lib
    LIBRARY			libc.lib
    LIBRARY			libpthread.lib
    LIBRARY			euser.lib
    
    OPTION CW -wchar_t on
    MACRO  _WCHAR_T_DECLARED
    
    
  7. Modify HelloWorld.cpp with the following code
    /
    ============================================================================
     Name		: HelloWorld.cpp
     Author	  : 
     Copyright   : Your copyright notice
     Description : Exe source file
    ============================================================================
    */
    #include	<iostream.h>
    #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;
    }
    
    

 


Deleting Hello World Project

  1. Select Hello World in the C/C++ Projects window. Right click project and clickDelete to open the Confirm Project Delete dialog box.

    Figure 6 Deleting Project

    Figure 7 Confirm Project Delete

  2. Click Yes to delete the project

This removes the HelloWorld Project from the current projects window. There is no re-import option available in Carbide so to retrieve the mmp modifications, delete the project and import it again.

 


Importing Hello World project in Carbide C++

  1. File > Import to open the Import dialog box.

    Figure 8 Import

  2. Click Next to open the File Import Wizard and select the bld.inf file.

    Figure 9 File Import Wizard

  3. Click Next and Select SDK and build configurations.

    Figure 10 SDK and build configurations

  4. Click Next and choose the project MMP file.

    Figure 11 MMP Selection

  5. Click Next to find project properties , click Finish.to find the Hello World project under C/C++ Projects window.

    Figure 12 Project Properties

 


Building Hello World Project

  1. Select HelloWorld project in C/C++ Projects window.
  2. Right click HelloWorld project, and click Build project . Find the Build Complete results with error listing in the console view.

    Figure 13 Build Project

    Figure 14 Console View

  3. Click the run button to run HelloWorld project

    Figure 15 Run Button

  4. Type HelloWorld on the Emulator and press enter to find the final output.

    Figure 16 Hello World

    Figure 17 Final Output

 


Changing the build configuration

  1. In the C/C++ Projects window, select HelloWorld project. Right click project, and click Active Build Configuration. Select the configuration from the submenu.

    Figure 18 Active Build Configuration

    Find the project in the selected configuration.


ŠNokia 2008

Back to top


This material, including documentation and any related computer programs, is protected by copyright controlled by Nokia. All rights are reserved. Copying, including reproducing, storing, adapting or translating, any or all of this material requires the prior written consent of Nokia. This material also contains confidential information, which may not be disclosed to others without the prior written consent of Nokia.

Nokia is a registered trademark of Nokia Corporation. S60 and logo is a trademark of Nokia Corporation. Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. Other company and product names mentioned herein may be trademarks or tradenames of their respective owners.