This page was last modified 05:13, 21 November 2007.
Open C target types
From Forum Nokia Wiki
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 S60 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 */
}
…
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Nokia related MIME types. | kerpow | Browsing and Mark-ups | 1 | 1970-01-01 02:00 |
| ChipFlip sample on a target device | thakki | Symbian Tools & SDKs | 0 | 2005-03-04 11:06 |
| Steps for porting the program from Emulater to the phone (Help) | alikhairat | Porting Symbian C++ to S60 | 29 | 2007-07-27 17:45 |
| Relating content types and snapshot encodings | jonawebb | Mobile Java Media (Graphics & Sounds) | 6 | 2006-10-21 00:55 |
| Nokia 6131 NFC Push Registry | mariosas | Near Field Communication | 21 | 2007-08-08 14:15 |
