Linking with MY_BASIC

Wang Renxin edited this page Jul 7, 2018 · 3 revisions

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.

Public functions

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 functions

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:

  1. Remove the static keyword
  2. Add an MBAPI attribute
  3. 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
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.