CreateLibrary
This feature is not supported on the Wolfram Cloud.

CreateLibrary["code",name]
compiles a string of C code and creates a library file.

CreateLibrary[File["path"],"name"]
compiles a C source file.

CreateLibrary[{file1,},name]
compiles a number of C source files into a library.

更多信息更多信息

  • To use CreateLibrary, you first need to load it using Needs["CCompilerDriver`"].
  • If CreateLibrary cannot find a suitable C compiler, it issues a message and returns $Failed.
  • The extension given to the library depends on the setting of $OperatingSystem.
  • In CreateLibrary[{file1,},name], each of the filei can be specified as "path" or File["path"].
  • The following options can be given:
  • "Compiler"Automaticthe compiler to use
    "CleanIntermediate"Automaticwhether temporary files should be deleted
    "CreateBinary"Truewhether the library file should be created
    "CompileOptions"""options to pass through to the compiler
    "CompilerInstallation"Automaticlocation of the compiler software
    "CompilerName"Automaticwhich compile command to use
    "Debug"Falsecompiles with debug information, does not clean the intermediate output, and prints the compile commands and output
    "Defines"{}C preprocessor defines to use for the build
    "ExtraObjectFiles"{}previously compiled object files to include in the executable
    "IncludeDirectories"{}directories to add to the include path
    "Language"Automaticwhat language the source code is in (can be used to assume source is C or C++ rather than relying on automatic detection)
    "Libraries"{}libraries to use to build the executable
    "LibraryDirectories"{}directories to add to the library lookup path
    "LinkerOptions"{}options passed to the linker
    "PreCompileCommands"""shell commands to run before compilation
    "PostCompileCommands"""shell commands to run after compilation
    "ShellCommandFunction"Nonefunction to call with the shell commands used for compilation
    "ShellOutputFunction"Nonefunction to call with the shell output of running the compilation commands
    "SystemCompileOptions"{}options to pass through to the compiler before "CompileOptions"
    "SystemIncludeDirectories"Automaticdirectories to locate Wolfram Language header files
    "SystemLibraries"AutomaticWolfram Language libraries
    "SystemLibraryDirectories"Automaticdirectories to locate Wolfram Language libraries
    "SystemLinkerOptions"{}options passed to the linker before "LinkerOptions"
    "TargetDirectory"Automaticthe directory in which the executable file should be created
    "TargetSystemID"$SystemIDthe system for which output should be generated
    "WorkingDirectory"Automaticthe directory in which temporary files should be generated
  • The "CleanIntermediate" option can take one of four settings. Automatic, the default, removes all intermediate files except on Windows, where the .exp and .lib files are preserved since they are needed when compiling files using the library. True removes all intermediate files. False preserves all intermediate files. Full removes all files in the working directory whether they are intermediate files or not.

范例范例打开所有单元关闭所有单元

基本范例  (1)基本范例  (1)

First, load the package:

In[1]:=
Click for copyable input

Define the library source:

In[2]:=
Click for copyable input

Create a library:

In[3]:=
Click for copyable input
Out[3]=

Use LibraryFunctionLoad to load a function from the library for use in the kernel:

In[4]:=
Click for copyable input
Out[4]=

Use the loaded function:

In[5]:=
Click for copyable input
Out[5]=