-
Notifications
You must be signed in to change notification settings - Fork 122
Linking with MY_BASIC
It is also possible to link with MY-BASIC as a library, instead of copying the kernel files to target projects. This page shows how to expose MY-BASIC functions to make a linkable library.
All functions tagged with MBAPI
in my_basic.h
are public functions. Although they were not declared as exposing by default in MY-BASIC, it is easy to modify that.
Different compilers recognize different compilation attributes specified by compiler vendors for symbol storage information. Consider picking proper attributes for your working compiler.
VS: uses __declspec(dllexport)
inside a shared library to export symbols, uses __declspec(dllimport)
when reference symbols from a shared library. In case of static linking no declspec
is required.
GCC: refers to "Visibility".
Xcode: refers to "Controlling Symbol Visibility".
Other compilers: refers to guide document provided by compiler vendors.
Use the more portable MBAPI
declaration as follow, to expose all MBAPI
functions:
#if !defined MBAPI
# if defined _MSC_VER
# if defined INTE_COMPILE /* Define INTE_COMPILE as export when build a DLL */
# define MBAPI __declspec(dllexport)
# else /* Otherwise import for referring */
# define MBAPI __declspec(dllimport)
# endif
# else
# define MBAPI __attribute__ ((visibility("default")))
# endif
#endif
Private refers to functions which are only "visible" by other functions in a single C compilation unit (a *.c file), and cannot be referenced outside that source file. There's no need to care about these functions for most cases.
Although you can expose these static function by changing the symbol visibility if you really wish to. Follow these steps to make it:
- Remove the
static
keyword - Add an
MBAPI
attribute - Make sure your project referencing the MY-BASIC library could include the declaration of exposed functions, you can simply add them to
my_basic.h
or declare them in your projects
- Principles
- Coding
- Data types
- Standalone shell
- Integration
- Customization
- More scripting API
- FAQ