cling/www/index.html
2017-06-06 15:45:25 +02:00

123 lines
5.1 KiB
HTML

<html>
<head>
<title>Cling</title>
<script data-main="scripts/cling" src="scripts/require.js"></script>
<link rel="stylesheet" href="style/import.css">
</head>
<body onload="selectMenu('index')">
<iframe seamless src="header.html" class="header" id="iheader"></iframe>
<div id="breadcrumb"></div>
<div id="content">
<div id="sidebar">
<!-- insert your sidebar items here -->
<iframe seamless class="sidebar" src="news.html"></iframe>
</div>
<div id="main">
<!-- insert the page content here -->
<h1>Cling interprets C++</h1>
<pre><code class = "cpp">
****************** CLING ******************
* Type C++ code and press enter to run it *
* Type .q to exit *
*******************************************
[cling]$ #include &lt;string&gt;
[cling]$ std::string s("abc");
[cling]$ s.find('b')
(std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::size_type) 1
[cling]$
</code></pre>
<p>
Cling is built on the top of LLVM and Clang libraries. In addition to standard interpreters it has a command line prompt and uses just-in-time (JIT) compiler. This kind of software application is commonly known as an interactive compiler.
<br/>
Cling started off as a contemporary, high-performance alternative of the current C++ interpreter in the ROOT project - CINT.
</p>
<h3>Why interpreting C++ with Cling?</h3>
<ul style="list-style-type:none">
<li>Learning C++
<p>
One use case of cling is to aid the C++ learning process. Offering imediate feedback the user can easily get familiar with the structures and spelling of the language.
</p>
</li>
<li>Creating scripts
<p>
The power of an interpreter lays as well in the compactness and ease of repeatedly running a small snippet of code - aka a script. This can be done in cling by inserting the bash-like style line:
</p>
<pre><code>
#!/usr/bin/cling
</code></pre>
</li>
<li>Rapid Application Development (RAD)
<p>
Cling can be used successfully for Rapid Application Development allowing for prototyping and proofs of concept taking advantage of dynamicity and feedback during the implementation process.
</p>
</li>
<li>Runtime-Generated Code
<p>
Sometime it's convenient to create code as a reaction to input
(user/network/configuration).
Runtime-generated code can interface with C++ libraries.
</p>
</li>
</ul>
<h3> Embedding Cling </h3>
<p>
The functionality of an application can be enriched by embedding Cling.
To embed Cling, the main program has to be provided. One of the things this main program has to do is initialize the Cling interpreter. There are optional calls to pass command line arguments to Cling. Afterwards, you can call the interpreter from any anywhere within the application.
</p>
<p>
For compilation and linkage the application needs the path to the clang and llvm libraries and the invocation is order dependent since the linker cannot do backward searches.
</p>
<pre><code>
g++ embedcling.cxx -std=c++11 -L/usr/local/lib
-lclingInterpreter -lclingUtils
-lclangFrontend -lclangSerialization -lclangParse -lclangSema
-lclangAnalysis -lclangEdit -lclangLex -lclangDriver -lclangCodeGen
-lclangBasic -lclangAST
`llvm-config
--libs bitwriter mcjit orcjit native option
ipo profiledata instrumentation objcarcopts`
-lz -pthread -ldl -ltinfo
-o embedcling
</code></pre>
<p>
Embedding cling requires the creation of the interpreter. Optionally compiler arguments and the resource directory of llvm can be passed. An example is the following:
</p>
<pre><code>
#include "cling/Interpreter/Interpreter.h"
int main(int argc, char** argv) {
const char* LLVMRESDIR = "/usr/local/"; //path to llvm resource directory
cling::Interpreter interp(argc, argv, LLVMRESDIR);
interp.declare("int p=0;");
}
</code></pre>
<p>A more complete example could be found in <a href="https://github.com/root-project/cling/tree/master/tools/demo" target="_blank">tools/demo/cling-demo.cpp</a></p>
<h3> Download </h3>
<p>
We are developing Cling according to the principle of Release early and release often. Binaries are available for <a href="https://root.cern.ch/download/cling/" target="_blank">download</a>.
</p>
<h3> Support </h3>
<p> Support is provided through a fast-response <a href="https://root.cern.ch/phpBB3/viewforum.php?f=21" target="_blank">forum</a>, where questions of all levels are welcomed. Queries can also be sent to our mailing list: cling-dev@cern.ch.
</p>
</div>
</div>
<iframe seamless class="footer" src="footer.html"></iframe>
</body>
</html>