CCodeGenerate[cfun,name,opts]
generates C code from the compiled function cfun using the name as the exported function name, and saves in the file name.c.
CCodeGenerate[cfun,name,filename]
generates output in filename.
CCodeGenerate[{cfun1,cfun2,…},{ name1,name2,…},filename]
generates C code from several compiled functions and saves in filename.
CCodeGenerate
CCodeGenerate[cfun,name,opts]
generates C code from the compiled function cfun using the name as the exported function name, and saves in the file name.c.
CCodeGenerate[cfun,name,filename]
generates output in filename.
CCodeGenerate[{cfun1,cfun2,…},{ name1,name2,…},filename]
generates C code from several compiled functions and saves in filename.
更多信息和选项
- To use CCodeGenerate, you first need to load it using Needs["CCodeGenerator`"].
- CCodeGenerate[cfun, name, File["filename"]] is also supported.
- CCodeGenerate can make standalone code or a Wolfram Library.
- The Wolfram Language contains the necessary headers and libraries for standalone code.
- You can generate a header for the generated code by setting "CodeTarget" to "WolframRTLHeader".
- The following option can be given:
-
"CodeTarget" "WolframRTL" the type of code to generate
范例
打开所有单元 关闭所有单元基本范例 (1)
Needs["CCodeGenerator`"]c = Compile[ {{x}}, x ^ 2];
file = CCodeGenerate[c, "fun"]FilePrint[file]Generate code from two compiled functions:
c1 = Compile[ {{x}}, x ^ 3];
file = CCodeGenerate[{c, c1}, {"fun", "fun1"}]FilePrint[file]Scope (1)
Needs["CCodeGenerator`"]Create two compiled functions for export:
c1 = Compile[ {{x}}, x ^ 2];c2 = Compile[{{x}}, Sin[x]];file = CCodeGenerate[{c1, c2}, {"fun1", "fun2"}, File["my_funs"]]FilePrint[file]Options (1)
CodeTarget (1)
Needs["CCodeGenerator`"]By default, standalone C code is generated:
c = Compile[ {{x}}, x ^ 2];
file = CCodeGenerate[c, "fun"];
FilePrint[file]This generates the header file for the export:
c = Compile[ {{x}}, x ^ 2];
file = CCodeGenerate[c, "fun", "CodeTarget" -> "WolframRTLHeader"];
FilePrint[file]技术笔记
相关指南
文本
Wolfram Research (2010),CCodeGenerate,Wolfram 语言函数,https://reference.wolfram.com/language/CCodeGenerator/ref/CCodeGenerate.html (更新于 2016 年).
CMS
Wolfram 语言. 2010. "CCodeGenerate." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2016. https://reference.wolfram.com/language/CCodeGenerator/ref/CCodeGenerate.html.
APA
Wolfram 语言. (2010). CCodeGenerate. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/CCodeGenerator/ref/CCodeGenerate.html 年
BibTeX
@misc{reference.wolfram_2026_ccodegenerate, author="Wolfram Research", title="{CCodeGenerate}", year="2016", howpublished="\url{https://reference.wolfram.com/language/CCodeGenerator/ref/CCodeGenerate.html}", note=[Accessed: 17-August-2026]}
BibLaTeX
@online{reference.wolfram_2026_ccodegenerate, organization={Wolfram Research}, title={CCodeGenerate}, year={2016}, url={https://reference.wolfram.com/language/CCodeGenerator/ref/CCodeGenerate.html}, note=[Accessed: 17-August-2026]}