# SimpleITK: compiling first C++ program

**URL:** https://discourse.itk.org/t/simpleitk-compiling-first-c-program/1026
**Category:** Beginner Questions
**Tags:** simpleitk
**Created:** [June 22, 2018, 8:33am UTC](https://discourse.itk.org/t/simpleitk-compiling-first-c-program/1026 "2018-06-22T08:33:34Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![szhorvat](https://discourse.itk.org/user_avatar/discourse.itk.org/szhorvat/32/384_2.png) [@szhorvat](https://discourse.itk.org/u/szhorvat)
#### Post date: [June 22, 2018, 8:33am UTC](https://discourse.itk.org/t/simpleitk-compiling-first-c-program/1026/1 "2018-06-22T08:33:35Z")

</div>

I managed to compile SimpleITK according to [the instructions](http://simpleitk.readthedocs.io/en/master/Documentation/docs/source/building.html), and now I would like to start using it from C++.

I am looking for guidance on compiling one of the basic examples such as `HelloWorld.cxx` or `SimpleGaussianFunctional.cxx` from the command line (macOS). I see that there is an `include` folder, which contains the required headers, and I can use them. There is also a `lib` folder with many `.a` files, but I am not sure which to link with (and how) to compile successfully.

Could someone give a short example of a compilation command?

Also, is `cmake` a requirement for building programs that use SimpleITK? (I do not mean building SimpleITK itself, but using it from my own program.)

My ultimate goal is to expose a few filters to a high-level language that is not supported by SWIG. I am not very familiar with `cmake`, and combining it with the build system that comes with this high-level language would make things even more difficult. I would very much prefer to start with the simplest possible compiler command line that can get the `HelloWorld.cxx` example compiled and working.

If there is a documentation page that explains how to build my own programs with SimpleITK, please do let me know. After extensive searching, I was unable to find one.

---

<div class="post-metadata">

### Author: ![szhorvat](https://discourse.itk.org/user_avatar/discourse.itk.org/szhorvat/32/384_2.png) [@szhorvat](https://discourse.itk.org/u/szhorvat)
#### Post date: [June 22, 2018, 10:51am UTC](https://discourse.itk.org/t/simpleitk-compiling-first-c-program/1026/2 "2018-06-22T10:51:11Z")

</div>

It seems that if I include _all_ the `.a` files from the `lib` directory, as well as the `ITK-prefix/lib` directory, then the executable is linked successfully, and it runs correctly. Is this a reasonable way of doing it?

I.e., compile with

```
c++ -std=c++11 someProg.cpp -I include/SimpleITK-1.1 lib/libSimpleITK*.a ITK-prefix/lib/*.a
```

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [June 22, 2018, 2:49pm UTC](https://discourse.itk.org/t/simpleitk-compiling-first-c-program/1026/3 "2018-06-22T14:49:59Z")

</div>

That is correct. It can be a simple matter of including just the SimpleITK include directory and all the ITK/SimpleITK libraries. Now, SimpleITK and ITK have a lot of configuration options so they may depend on system headers or additional third party libraries and headers depending on how they are configured. SimpleITK as a reasonable “clean” interface, so this is a reasonable way to do things.

If you are able to use CMake, all this information is encoded into the configurations and exports. Since each library knows it dependencies, it may result in fewer libraries being used.
