Setting Search Paths for MapBasic Include and Module Files - MapBasic - 2023

MapInfo MapBasic Reference

Product type
Software
Portfolio
Locate
Product family
MapInfo
Product
MapInfo > MapBasic
Version
2023
Language
English
Product name
MapBasic
Title
MapInfo MapBasic Reference
First publish date
1985
Last updated
2023-09-12
Published on
2023-09-12T16:32:32.686312

To make it easier to develop MapBasic libraries of definitions and modules, you can set environment variables for search paths for Include (.def) files when compiling and Module (.mbo) files when linking. By default, MapBasic will search for these files first in the path specified in your MapBasic code and then under the folder where MapBasic is installed. By setting these environment variables you can specify additional folders to search after the path specified in your code but before the MapBasic folder. The environment variables are called MBINCLUDE and MBMODULE for Include and Module files, respectively, and their values should be set to a semi-colon delimited list of folders to search. MapBasic will search the folders specified and all sub-folders beneath them.

You can set environment variables via the Advanced System Settings on your system. The variables must be set before you run MapBasic for them to be effective.

To set additional search folders for Include files, set the environment variable MBINCLUDE. For example, if you have libraries of .def files in or beneath the folders C:\My MapBasic Library and C:\Work, set the MBINCLUDE environment variable as follows:

Do not use quotes around the folder names even if the path contains spaces.

To set additional search folders for Module files, similarly set the environment variable MBMODULE. For example, if you have libraries of .mbo files in or beneath the folder C:\My MapBasic Library, set the MBMODULE environment variable as follows:

Here is an example of section of MapBasic code:
Include “mapbasic.def”
Include “utilities.def”
Include “myapplication.def”

Assuming you set your environment variables as above, when compiling MapBasic will search for these .def files first in the folder where the file your are compiling is located, then under C:\My MapBasic Library and its subfolders, next under C:\Work and its subfolders, and last under the folder where MapBasic was installed. If the file utilities.def, for example, is used by multiple applications you’ve written you can put it somewhere under C:\My MapBasic Library or C:\Work and MapBasic can find it without you having to specify the path in the code.

Similarly your project (.mbp) file could look as follows:
[Link]Application=myapplication.mbx
Module=myapplication.mbo
Module=library.mbo

If the file library.mbo, for example, is used by multiple applications you’ve written you can put it somewhere under C:\My MapBasic Library and MapBasic can find it without you having to specify the path in the project file.