cling/www/index.html

123 lines
5.1 KiB
HTML
Raw Normal View History

2016-02-23 20:16:10 +03:00
<html>
<head>
2016-07-20 16:35:07 +03:00
<title>Cling</title>
<script data-main="scripts/cling" src="scripts/require.js"></script>
<link rel="stylesheet" href="style/import.css">
2016-02-23 20:16:10 +03:00
</head>
2016-07-20 16:35:07 +03:00
<body onload="selectMenu('index')">
<iframe seamless src="header.html" class="header" id="iheader"></iframe>
2016-02-23 20:16:10 +03:00
<div id="breadcrumb"></div>
<div id="content">
2016-07-20 17:23:03 +03:00
<div id="sidebar">
2016-02-23 20:16:10 +03:00
<!-- insert your sidebar items here -->
2016-07-20 17:23:03 +03:00
<iframe seamless class="sidebar" src="news.html"></iframe>
2016-02-23 20:16:10 +03:00
</div>
<div id="main">
<!-- insert the page content here -->
2016-07-20 16:45:21 +03:00
<h1>Cling interprets C++</h1>
2016-02-25 17:46:30 +03:00
<pre><code class = "cpp">
****************** CLING ******************
* Type C++ code and press enter to run it *
* Type .q to exit *
*******************************************
2016-07-20 16:45:21 +03:00
[cling]$ #include &lt;string&gt;
2016-02-25 17:46:30 +03:00
[cling]$ std::string s("abc");
[cling]$ s.find('b')
2016-07-20 16:45:21 +03:00
(std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::size_type) 1
2016-02-25 17:46:30 +03:00
[cling]$
</code></pre>
2016-02-23 20:16:10 +03:00
<p>
2016-02-25 17:46:30 +03:00
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.
2016-02-23 20:16:10 +03:00
<br/>
Cling started off as a contemporary, high-performance alternative of the current C++ interpreter in the ROOT project - CINT.
</p>
2016-02-25 17:46:30 +03:00
<h3>Why interpreting C++ with Cling?</h3>
2016-02-23 20:16:10 +03:00
<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:
2016-07-20 16:45:21 +03:00
</p>
2016-02-25 17:46:30 +03:00
<pre><code>
2016-02-23 20:16:10 +03:00
#!/usr/bin/cling
2016-02-25 17:46:30 +03:00
</code></pre>
2016-02-23 20:16:10 +03:00
</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>
2016-02-25 17:46:30 +03:00
Sometime it's convenient to create code as a reaction to input
(user/network/configuration).
Runtime-generated code can interface with C++ libraries.
2016-02-23 20:16:10 +03:00
</p>
</li>
</ul>
2016-02-25 17:46:30 +03:00
<h3> Embedding Cling </h3>
2016-02-23 20:16:10 +03:00
<p>
2016-02-25 17:46:30 +03:00
The functionality of an application can be enriched by embedding Cling.
2016-02-23 20:16:10 +03:00
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>
2016-02-25 17:46:30 +03:00
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.
2016-02-23 20:16:10 +03:00
2016-07-20 16:45:21 +03:00
</p>
2016-02-25 17:46:30 +03:00
<pre><code>
g++ embedcling.cxx -std=c++11 -L/usr/local/lib
2016-02-23 20:16:10 +03:00
-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
2016-02-25 17:46:30 +03:00
-o embedcling
</code></pre>
2016-02-23 20:16:10 +03:00
<p>
2016-02-25 17:46:30 +03:00
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:
2016-07-20 16:45:21 +03:00
</p>
2016-02-25 17:46:30 +03:00
<pre><code>
2016-02-23 20:16:10 +03:00
#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;");
}
2016-02-25 17:46:30 +03:00
</code></pre>
2016-02-23 20:16:10 +03:00
2017-06-06 16:28:01 +03:00
<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>
2016-02-23 20:16:10 +03:00
2016-02-25 17:46:30 +03:00
<h3> Download </h3>
2016-02-23 20:16:10 +03:00
<p>
2016-02-25 17:46:30 +03:00
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>.
2016-02-23 20:16:10 +03:00
</p>
2016-02-25 17:46:30 +03:00
<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.
2016-02-23 20:16:10 +03:00
</p>
</div>
2016-07-20 17:23:03 +03:00
</div>
<iframe seamless class="footer" src="footer.html"></iframe>
2016-02-23 20:16:10 +03:00
</body>
</html>