Skip to content

Commit 84543fe

Browse files
committed
Update CBMC tutorial with compilation instructions
The COMPILING.md document has been significantly updated since this tutorial was first added. The tutorial thus points to COMPILING.md as the source of truth for how to initially build CBMC.
1 parent 03ab5c7 commit 84543fe

File tree

1 file changed

+28
-38
lines changed

1 file changed

+28
-38
lines changed

doc/architectural/howto.md

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,27 @@ to the basic data structures and workflow needed for contributing to
1616

1717
## Initial setup
1818

19-
Clone the [CBMC repository][cbmc-repo] and build it:
19+
Clone the [CBMC repository][cbmc-repo] and build it. The build instructions are
20+
written in a file called COMPILING.md in the top level of the repository. I
21+
recommend that you build using CMake---this will place all of the CBMC tools in
22+
a single directory, which you can add to your `$PATH`. For example, if you built
23+
the codebase with the following two commands at the top level of the repository:
24+
25+
cmake -DCMAKE_CXX_FLAGS=-fcolor-diagnostics \
26+
-DCMAKE_BUILD_TYPE=Debug \
27+
-DWITH_JBMC=OFF \
28+
-DCMAKE_CXX_COMPILER=/usr/bin/clang++ \
29+
-DCMAKE_C_COMPILER=/usr/bin/clang \
30+
-B build -S .
31+
cmake --build build
32+
33+
then all the CBMC binaries will be built into `build/bin`, and you can run the
34+
following commands to make CBMC invokable from your terminal.
2035

21-
git clone https://github.com/diffblue/cbmc.git
22-
cd cbmc/src
23-
make minisat2-download
24-
make
36+
# Assuming you cloned CBMC into ~/code
37+
export PATH=~/code/cbmc/build/bin:$PATH
38+
# Add to your shell's startup configuration file so that you don't have to run that command every time.
39+
echo 'export PATH=~/code/cbmc/build/bin:$PATH' >> .bashrc
2540

2641
Ensure that [graphviz][graphviz] is installed on your system (in
2742
particular, you should be able to run a program called `dot`). Install
@@ -30,48 +45,29 @@ particular, you should be able to run a program called `dot`). Install
3045
# In the src directory
3146
doxygen doxyfile
3247
# View the documentation in a web browser
33-
firefox doxy/html/index.html
48+
firefox ~/code/cbmc/doc/html/index.html
3449

3550
If you've never used doxygen documentation before, get familiar with the
3651
layout. Open the generated HTML page in a web browser; search for the
3752
class `goto_programt` in the search bar, and jump to the documentation
3853
for that class; and read through the copious documentation.
3954

40-
The build writes executable programs into several of the source
41-
directories. In this tutorial, we'll be using binaries inside the
42-
`cbmc`, `goto-instrument`, and `goto-cc` directories. Add these
43-
directories to your `$PATH`:
44-
45-
# Assuming you cloned CBMC into ~/code
46-
export PATH=~/code/cbmc/src/goto-instrument:~/code/cbmc/src/goto-cc:~/code/cbmc/src/cbmc:$PATH
47-
# Add to your shell's startup configuration file so that you don't have to run that command every time.
48-
echo 'export PATH=~/code/cbmc/src/goto-instrument:~/code/cbmc/src/goto-cc:~/code/cbmc/src/cbmc:$PATH' >> .bashrc
49-
50-
Optional: install an image viewer that can read images on stdin.
51-
I use [feh][feh].
52-
5355
[cbmc-repo]: https://github.com/diffblue/cbmc/
5456
[doxygen]: http://www.stack.nl/~dimitri/doxygen/
5557
[graphviz]: http://www.graphviz.org/
56-
[feh]: https://feh.finalrewind.org/
57-
5858

5959

6060
## Whirlwind tour of the tools
6161

62-
CBMC's code is located under the `cbmc` directory. Even if you plan to
62+
CBMC's code is located under the `src` directory. Even if you plan to
6363
contribute only to CBMC, it is important to be familiar with several
6464
other of cprover's auxiliary tools.
6565

6666

6767
### Compiling with `goto-cc`
6868

69-
There should be an executable file called `goto-cc` in the `goto-cc`
70-
directory; make a symbolic link to it called `goto-gcc`:
71-
72-
cd cbmc/src/goto-cc
73-
ln -s "$(pwd)/goto-cc" goto-gcc
74-
69+
If you built using CMake on Unix, you should be able to run the
70+
`goto-gcc` command.
7571
Find or write a moderately-interesting C program; we'll call it `main.c`.
7672
Run the following commands:
7773

@@ -102,16 +98,10 @@ structured programming constructs.
10298

10399
Find or write a small C program (2 or 3 functions, each containing a few
104100
varied statements). Compile it using `goto-gcc` as above into an object
105-
file called `main`. If you installed `feh`, try the following command
106-
to dump a control-flow graph:
107-
108-
goto-instrument --dot main | tail -n +2 | dot -Tpng | feh -
109-
110-
If you didn't install `feh`, you can write the diagram to the file and
111-
then view it:
101+
file called `main`. You can write the diagram to a file and then view it:
112102

113-
goto-instrument --dot main | tail -n +2 | dot -Tpng > main.png
114-
Now open main.png with an image viewer
103+
goto-instrument --dot main.goto | tail -n +2 | dot -Tpng > main.png
104+
open main.png
115105

116106
(the invocation of `tail` is used to filter out the first line of
117107
`goto-instrument` output. If `goto-instrument` writes more or less
@@ -148,7 +138,7 @@ At some point in that function, there will be a long sequence of `if` statements
148138
**Task:** Add a `--greet` switch to `goto-instrument`, taking an optional
149139
argument, with the following behaviour:
150140

151-
$ goto-instrument --greet main
141+
$ goto-instrument --greet main.goto
152142
hello, world!
153143
$ goto-instrument --greet Leperina main
154144
hello, Leperina!

0 commit comments

Comments
 (0)