1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
# Quick Setup (using CMake) {#setup}
<b>Learning Objective:</b><br>
In this short guide you will learn how to set up SeqAn and how to compile a small example to test whether everything
works.
\tutorial_head{Easy, 30 Minutes, No prerequisites, }
[TOC]
<br>
# Software
Requirements:
- gcc >= 7
- cmake >= 3.4
- git
SeqAn3 requires a compiler with full C++20 support *or* GCC >= 7. Current versions of LLVM/Clang and VisualStudio/MSVC are **not supported**.
We will briefly explain how to install GCC-7 on some popular operating systems, but we recommend using the latest version of GCC available. For more information refer to your operating system's documentation.
**Ubuntu >= 18.04**
```
sudo apt install g++
```
**Ubuntu < 18.04**
```
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt install g++-7
```
**MacOS** using [Homebrew](https://brew.sh/)
```
brew install gcc@7
```
**MacOS** using [MacPorts](https://www.macports.org/)
```
sudo port install gcc-7
```
**Linux** using [conda](https://conda.io)
```
conda create -n gcc7 -c quantstack gcc-7 libgcc-7
conda activate gcc7
```
This will put GCC-7 in a separate environment called `gcc7` which can be activated via `conda activate gcc7` and deactivated via `conda deactivate gcc7`.
\note \htmlonly <div class=\"assignment\"> <details><summary><b>Known Issue:</b></summary> \endhtmlonly If you encounter the error <code>/usr/lib/x86_64-linux-gnu/libstdc++.so.6: version 'CXXABI_1.3.11' not found</code>, you have to set the LD_LIBRARY_PATH:
```
export LD_LIBRARY_PATH=/home/user/miniconda3/envs/gcc7/lib/
```
where `/home/user/miniconda3/` is the path to your conda installation. \htmlonly </details> </div> \endhtmlonly
\attention After installing, `g++ --version` should print the desired version. If not, you may have to use, for example, `g++-7 --version` or even specify the full path to your executable.
Similarly you need to install cmake and git, e.g. `apt install cmake git`.
# Directory Structure
For this project, we recommend following directory layout:
```
tutorial
├── source
├── build
└── seqan3
```
To set these directories up you can follow this script (note the <b>\--recurse-submodules</b> when cloning SeqAn3):
```
mkdir tutorial
cd tutorial
mkdir build
mkdir source
git clone --recurse-submodules https://github.com/seqan/seqan3.git
```
The output of the command ``` tree -L 2 ``` should now look like this:
```
.
├── build
├── seqan3
│ ├── build_system
│ ├── CHANGELOG.md
│ ├── CMakeLists.txt
│ ├── CODE_OF_CONDUCT.md
│ ├── CONTRIBUTING.md
│ ├── doc
│ ├── include
│ ├── LICENSE.md
│ ├── README.md
│ ├── submodules
│ └── test
└── source
8 directories, 6 files
```
# Compiling and Running
To test whether everything works, we will now compile and run a small example.
First we create the file `hello_world.cpp` in the `source` directory with the following contents:
\include hello_world.cpp
To compile it we first create a `CMakeLists.txt` file in the `source` directory:
```cmake
cmake_minimum_required (VERSION 3.4)
project (seqan3_tutorial CXX)
find_package (SeqAn3 3.0.0 REQUIRED HINTS "${CMAKE_SOURCE_DIR}/../seqan3/build_system")
add_executable (hello_world hello_world.cpp)
target_link_libraries (hello_world seqan3::seqan3)
```
The directories should now look like this:
```
tutorial
├── source
├── CMakeLists.txt
└── hello_world.cpp
├── build
└── seqan3
├── CMakeLists.txt
├── LICENSE
...
```
Now we can switch to the directory `build` and run:
```bash
cmake ../source
make
./hello_world
```
The output should be `Hello world`.
\remark Depending on the standard C++ on your system, you may need to specify the compiler via `-DCMAKE_CXX_COMPILER=`, for example:
```bash
cmake ../source -DCMAKE_CXX_COMPILER=/path/to/executable/g++-7
```
\note In some situations it can happen that the correct assembler is not found.
You will see an error during the cmake configuration that says something like: `... could not understand flag m ...`.
In this case you can try to export the Path:
```
export PATH=/util/bin:$PATH
```
and try running cmake again.
# Adding a new source file to your project
If you create a new `cpp` file and want to compile it, you need to add another `add_executable` and
`target_link_libraries` directive to you `CMakeLists.txt`.
For example, after adding `another_program.cpp` your `CMakeLists.txt` may look like this:
```cmake
cmake_minimum_required (VERSION 3.4)
project (seqan3_tutorial CXX)
find_package (SeqAn3 3.0.0 REQUIRED HINTS "${CMAKE_SOURCE_DIR}/../seqan3/build_system")
add_executable (hello_world hello_world.cpp)
add_executable (another_program another_program.cpp)
target_link_libraries (hello_world seqan3::seqan3)
target_link_libraries (another_program seqan3::seqan3)
```
|