Troubleshooting

This topic describes how to troubleshoot issues that you may face while writing or building Std C++ code on the Symbian platform.

Errors while building Std C++ Code

Problem

You may get a build error when you create a static library as illustrated in the following code and link it with an STDEXE .

The .mmp file of the static library:

       
        
       
       //operator_new_failure_example_lib.mmp
Target             operator_new_failure_example_lib.lib
Targettype        lib
Source            op_new_in_lib.cpp
Systeminclude        /epoc32/include/stdapis/stlportv5
Systeminclude        /epoc32/include/stdapis
      

The .cpp file of operator new reference in the static library example:

       
        
       
       // op_new_in_lib.cpp contents
#include <new>
int doSomething()
    {
    try
        {
        int *ptr = new int(0); // This refers the StdC++ operator new
        //do something moreā€¦
        }
        catch (std::bad_alloc)
        {
        return 1;
        }
    delete ptr;
    return 0;
    }
      

The .mmp file of the STDEXE that links with the static library:

       
        
       
       //operator_new_failure_example.mmp
Target             operator_new_failure_example.exe
Targettype        stdexe
Source            op_new_in_stdexe.cpp
Systeminclude        /epoc32/include/stdapis/stlportv5
Systeminclude        /epoc32/include/stdapis
Library            libstdcppv5.lib libc.lib
Staticlibrary        operator_new_failure_example_lib.lib
Capability        all -tcb
      

The .cpp file of operator new reference in static library example:

       
        
       
       // op_new_in_stdexe.cpp contents looks as follows:
int main()
    {
    // the doSomething function is defined in the static library operator_new_failure_example_lib.lib that this exe is linking against.
    return doSomething();
    }
      

Solution

The build error is caused because this code violates rule 5 under the Guidelines for Writing Standard C++ Libraries section. As per the rule, a static library of target type LIB cannot be linked against an STDEXE or STDDLL , unless it has the MMP keyword, STDCPP in its .mmp file.

You can fix the build error by adding STDCPP in the operator_new_failure_example_lib.mmp file as shown in the following code:

       
        
       
       //operator_new_failure_example_lib.mmp
Target             operator_new_failure_example_lib.lib
Targettype        lib
//The STDCPP keyword specifies Standard C++ 
STDCPP
Source            op_new_in_lib.cpp
Systeminclude        /epoc32/include/stdapis/stlportv5
Systeminclude        /epoc32/include/stdapis