Symbian3/SDK/Source/GUID-A2031A61-3319-4FBA-BC71-AC1327182053.dita
changeset 7 51a74ef9ed63
child 8 ae94777fff8f
equal deleted inserted replaced
6:43e37759235e 7:51a74ef9ed63
       
     1 <?xml version="1.0" encoding="utf-8"?>
       
     2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
       
     3 <!-- This component and the accompanying materials are made available under the terms of the License 
       
     4 "Eclipse Public License v1.0" which accompanies this distribution, 
       
     5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
       
     6 <!-- Initial Contributors:
       
     7     Nokia Corporation - initial contribution.
       
     8 Contributors: 
       
     9 -->
       
    10 <!DOCTYPE concept
       
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
       
    12 <concept id="GUID-A2031A61-3319-4FBA-BC71-AC1327182053" xml:lang="en"><title>Getting
       
    13 started with C++ Standard Library</title><shortdesc>The Standard C++ library depends on P.I.P.S.. The user must have
       
    14 the P.I.P.S. components installed before using the library.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
       
    15 <section id="GUID-D42A187D-603E-4D66-BAA8-86782B9C2717"><title>C++ IOstream
       
    16 and Standard Template Library Documentation</title><p>C++ IOStream library
       
    17 documentation can be found at <xref href="http://www.slac.stanford.edu/comp/unix/gnu-info/iostream_toc.html" scope="external">http://www.slac.stanford.edu/comp/unix/gnu-info/iostream_toc.html</xref>.</p><p>Similarly,
       
    18 Standard Template Library (STL) documentation can be found at <xref href="http://www.informatik.uni-freiburg.de/~danlee/fun/STL-doc/STL.html" scope="external">http://www.informatik.uni-freiburg.de/~danlee/fun/STL-doc/STL.html</xref>.</p></section>
       
    19 <section id="GUID-BF521201-7BE5-4AC5-8D35-1E15AC4887C7-GENID-1-8-1-11-1-1-9-1-5-1-3-2"><title>Changes to
       
    20 the MMP file</title><p><b>Add needed libraries used by the MMP file structure: </b></p><p>If
       
    21 developers want to use any of Standard C++ library, they must link to the
       
    22 corresponding library in the MMP file using the <codeph>LIBRARY</codeph> keyword.</p><p>If
       
    23 the application has <codeph>main()</codeph> as the entry point, the library <filepath>libcrt0.lib</filepath> must
       
    24 be specified as the first library otherwise, it results in linker errors.
       
    25 The user must link to the Symbian platform <filepath>euser.dll</filepath>.
       
    26 This is required since the static library uses some of the services of the
       
    27 Symbian platform, such as, creating cleanup stack, and having a top level
       
    28 TRAP. All these details are hidden from the developer. The developer will
       
    29 write the application as if it were for the UNIX environment.</p><codeblock xml:space="preserve">STATICLIBRARY  libcrt0.lib
       
    30 LIBRARY        libc.lib 
       
    31 LIBRARY        euser.lib  // Needed in order to use Symbian services
       
    32 </codeblock><p>The <filepath>libcrt0.lib</filepath> library is required for
       
    33 writing to <codeph>E32Main</codeph> within our application (EXE). This static
       
    34 library has an implementation of <codeph>E32Main</codeph> within which it
       
    35 calls the library initialization method followed by calling main written by
       
    36 the developer. This static library also retrieves command-line arguments and
       
    37 passes the same to main.</p><p>If the application has <codeph>E32Main()</codeph> as
       
    38 an entry point, there is no need to link to <filepath>libcrt0.lib</filepath> like
       
    39 in the example below.</p><codeblock xml:space="preserve">LIBRARY         libc.lib 
       
    40 LIBRARY         euser.lib</codeblock><p><b>Add required include paths</b></p><codeblock xml:space="preserve">SYSTEMINCLUDE   \epoc32\include\stdapis
       
    41 SYSTEMINCLUDE   \epoc32\include\stdapis\sys
       
    42 SYSTEMINCLUDE   \epoc32\include\stdapis\stlport 
       
    43 </codeblock><p><b>Linking of <codeph>libstdcpp</codeph></b></p><p>Following
       
    44 snippet shows how to perform the linking to <codeph>libstdcpp</codeph> on
       
    45 an emulator: </p><codeblock xml:space="preserve">#ifdef EPOC32
       
    46 LIBRARY  libstdcpp.lib
       
    47 #else
       
    48 FIRSTLIB ../udeb/libstdcpp.lib
       
    49 STATICLIBRARY    eexe.lib 
       
    50 #endif</codeblock><p>Add the below option and macro in the MMP file</p><codeblock xml:space="preserve">//This is required even if the wchar type is not used.
       
    51 OPTION CW -wchar_t on 
       
    52 MACRO  _WCHAR_T_DECLARED</codeblock><note> Standard C++ applications may require
       
    53 more stack space. The recommended stack size is 10K. To set the stack size
       
    54 to 10K add: </note><codeblock xml:space="preserve">EPOCSTACKSIZE 0x10000</codeblock><p>in the MMP
       
    55 file.</p></section>
       
    56 <section id="GUID-BF521201-7BE5-4AC5-8D35-1E15AC4887C7-GENID-1-8-1-11-1-1-9-1-5-1-3-3"><title>Example using <codeph>main()</codeph></title> 
       
    57      <p>A simple example using <codeph>main()</codeph> as an entry point is
       
    58 described below. The example writes a text to a console.</p><ul>
       
    59 <li><p>Modify the MMP file as mentioned before.</p></li>
       
    60 <li><p>Do usual C++ style coding.</p></li>
       
    61 </ul><codeblock xml:space="preserve">//  Include Files  
       
    62 #include &lt;iostream&gt;
       
    63 #include &lt;cstring&gt;
       
    64 // This is a GCCE toolchain workaround needed when compiling with GCCE
       
    65 // and using main() entry point
       
    66 #ifdef __GCCE__
       
    67 
       
    68 // This is a GCCE toolchain workaround needed when compiling with GCCE
       
    69 // and using main() entry point
       
    70 #ifdef __GCCE__
       
    71 
       
    72 #include &lt;staticlibinit_gcce.h&gt;
       
    73 #endif
       
    74 
       
    75 using namespace std;
       
    76 
       
    77 class myclass {
       
    78 public:
       
    79   void show(){cout&lt;&lt;"Hello World\n"; }
       
    80 } ;
       
    81 
       
    82 int main()
       
    83 {
       
    84   myclass obj;
       
    85   obj.show();
       
    86   cout&lt;&lt;"Press a character to exit!";
       
    87   int c = getchar();
       
    88   return 0;
       
    89 }
       
    90 </codeblock></section>
       
    91 </conbody></concept>