get and set C compiler options for generating wrappers used by define_external
When the WRAPPER option is used with define_external, a C file is created, compiled and linked into Maple. This new library, called a wrapper library, contains the code necessary to translate Maple data types into data types recognized by C programs.
To compile the wrapper library a compiler must be installed and recognized by the system. In most cases, if the compiler is in the system PATH, and all associated environment variables are set, then the wrapper generation and compilation will work "out of the box". Maple is preprogrammed to use the vendor supplied C compiler to compile most wrappers on most platforms. To use a non-standard compiler, alternate version of a compiler, or custom setup, change the COMPILE_OPTIONS Record.
The default compiler setup on Windows is to use the Microsoft Visual C compiler (MSVC). This configuration may change in future releases of Maple now that it ships with the Watcom C compiler on 32-bit Windows. To use the installed Watcom compiler execute the command define_external(WATCOM). To switch back to MSVC, use the command, define_external(MSVC). Executing either of these commands will clear any changes previously made to the COMPILE_OPTIONS record.
The COMPILE_OPTIONS argument by itself in a call to define_external returns a Record module containing default or current compile and link settings used for building the generated wrapper library. These options are globally settable by changing any of the module exports, or locally by passing the equation moduleExportName=value as an argument to define_external.
The compile and link commands are assembled by calling the COMPILE_COMMAND and LINK_COMMAND procedures defined in the COMPILE_OPTIONS Record. These procedures make use of the other definitions in the COMPILE_OPTIONS Record to formulate a command string that is executed by the ssystem command.
The COMPILE_OPTIONS available are:
name of the compiler executable
miscellaneous flags passed to the compiler
indicates that the file is only to be compiled. The compiler will generate an object file. A separate linker command is needed to create a shared library from the object file.
used by the compiler to specify the object file name. The compiler command uses COBJ_FLAG || FILE || OBJ_EXT to name the object file.
the procedure that generates the compile command. This procedure must return a string that will be executed by ssystem. It is not usually necessary to change the default.
".dll" or ".so"
the shared library name extension.
used in combination with the FUNCTION option to name the function to be exported from the shared library. This is unassigned or set to NULL on platforms that export all symbols by default.
the base name of the file to be complied. The file extension is filled in (ie. to compile "foo.c", set FILE="foo" and FILE_EXT=".c"). When FILE is set to NULL the system generates a file name based on the function name.
the file extension.
the name of the external function defined in the wrapper library. The system generates a FUNCTION name if this is left unassigned or is set to NULL.
precedes directories in the INC_PATH.
specifies directories to search for header files. Use an expression sequence to specify more than one directory. For example, INC_PATH=( "/maple/extern/include", "/users/jdoe/include").
name of the library which contains the external function to call. This option must be specified in every call to define_external. Manually assigned values will be ignored.
specifies other libraries that need to be linked with the wrapper library to resolve all external symbols. Use an expression sequence to specify more than one directory. For example, LIBS=( "/opt/compiler/libext.so", "/users/jdoe/lib/libtools.so").
precedes directories in the LIB_PATH.
specifies the directories to search for libraries. Use an expression sequence to specify more than one directory. For example, LIB_PATH=( "/maple/bin.SYS", "/users/jdoe/lib").
specifies the name of the linker executable.
the procedure that generates the linker command. The procedure must return a string that will be executed by ssystem. Set this to NULL if the compile command also does the linking.
specifies the miscellaneous flags passed to the linker, including those that cause the linker to build a shared library.
used by the linker to specify the target library name. The linker uses cat(LOBJ_FLAG,FILE,DLL_EXT) to name the shared library.
".o" or ".obj"
the object file extension.
specifies the system libraries to link with the wrapper library to resolve all external symbols.
To view the generated compiler and linker commands when executing define_external, set infolevel to 3 or higher.
The following example shows how to set up the GNU compiler on a machine running Solaris. The gcc compiler requires a space between -o and the object name. Modifying the COBJ_FLAG allows this to be easily done.
p ≔ define_external⁡'COMPILE_OPTIONS':
pCOMPILER ≔ gcc
pCOBJ_FLAG ≔ -o
Subsequently a command like the following will use the new options.
Download Help Document
What kind of issue would you like to report? (Optional)