×
Namespaces

Variants
Actions

Open C target types

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: ebra (20 Nov 2007)
Last edited: hamishwillee (27 Jul 2012)

Contents

Introduction

The conventional way of defining the entry point for a Symbian OS executable is by including "E32Main" in the application source.

In a native Symbian OS executable, the functions and data symbols with extern linkage are exported only if IMPORT_C/EXPORT_C declarations are found in the header or source files.

Since Symbian 3rd Edition FP2, you can define the entry point for an executable by including "main" instead of "E32Main". With this approach, developers may easily port their C/C++ code to Symbian OS platforms with less changes to the original source.

In a STDDLL executable, all functions and data symbols with extern linkage are exported by default without IMPORT_C/EXPORT_C declarations in the header or source files.

If your DLL is using writable static data, you have to inform the build system about it (if not done, building for ARM target will fail). This is done by adding the keyword EPOCALLOWDLLDATA to the MMP-file of the library.

EXE

// HelloOpenC.mmp
TARGET HelloOpenC.exe
TARGETTYPE EXE
UID 0x100039CE 0xA0001314
CAPABILITY NONE
 
SOURCEPATH ..\src
SOURCE HelloOpenC.c
 
SYSTEMINCLUDE \epoc32\include
SYSTEMINCLUDE \epoc32\include\stdapis
 
 
// This must be specified as the first library
// when using main() entry point
STATICLIBRARY libcrto.lib
 
LIBRARY libc.lib
LIBRARY euser.lib

STDEXE

// HelloOpenC.mmp
TARGET HelloOpenC.exe
TARGETTYPE STDEXE
UID 0x20004C45 0xA0001314
CAPABILITY NONE
 
SOURCEPATH ..\src
SOURCE HelloOpenC.c
 
SYSTEMINCLUDE \epoc32\include
LIBRARY libc.lib

PS: No need to specify the SYSTEMINCLUDE path for Open C headers. No need to link against libcrt0.lib and euser.lib.

DLL

IMPORT_C is used to specify that a function is made available for linkage – IMPORT_C is added to the function declaration.

This is needed since Symbian static libraries are linked by ordinal rather than function name. A DEF file links the ordinal to function name. The DEF file is created when a library is built.

Similarly, you have to add EXPORT_C to corresponding function definitions.

// sampledll.mmp
TARGET sampledll.dll
TARGETTYPE DLL
UID 0x1000008d 0x12213443

// Open C libc is required
LIBRARY libc.lib
/* sampledll.h */
#ifdef SAMPLEDLL_H
#define SAMPLEDLL_H
/* Make the header C++ friendly using extern “C” */
#ifdef __cplusplus
extern "C" {
#endif
IMPORT_C int Func1();

#ifdef __cplusplus
}
#endif
#endif /* SAMPLEDLL_H */
/* sampledll.c */
#include “sampledll.h”
...
EXPORT_C int Func1() {
/* Some code */
}
...

STDDLL

// sampledll.mmp
TARGET sampledll.dll
TARGETTYPE STDDLL
UID 0x20004C45 0x12213443

// Open C libc is required
LIBRARY libc.lib
/* sampledll.h */

/* No need for IMPORT_C with STDDLL target type */
int Func1();

/* sampledll.c */
#include “sampledll.h”

/* No need for EXPORT_C with STDDLL target type */
int Func1() {
/* Some code */
}
This page was last modified on 27 July 2012, at 08:15.
18 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×