{"id":25453054,"url":"https://github.com/aljo242/modern-cpp","last_synced_at":"2025-05-16T13:10:59.077Z","repository":{"id":44706958,"uuid":"452721027","full_name":"aljo242/modern-cpp","owner":"aljo242","description":"Learning modern C++ ","archived":false,"fork":false,"pushed_at":"2022-01-31T14:10:38.000Z","size":40,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-17T23:43:06.309Z","etag":null,"topics":["cpp"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aljo242.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"aljo242"}},"created_at":"2022-01-27T14:45:31.000Z","updated_at":"2022-01-29T21:12:59.000Z","dependencies_parsed_at":"2022-09-13T22:10:59.995Z","dependency_job_id":null,"html_url":"https://github.com/aljo242/modern-cpp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"cpp-best-practices/gui_starter_template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aljo242%2Fmodern-cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aljo242%2Fmodern-cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aljo242%2Fmodern-cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aljo242%2Fmodern-cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aljo242","download_url":"https://codeload.github.com/aljo242/modern-cpp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254535822,"owners_count":22087399,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp"],"created_at":"2025-02-17T23:42:26.708Z","updated_at":"2025-05-16T13:10:59.056Z","avatar_url":"https://github.com/aljo242.png","language":"C++","funding_links":["https://github.com/sponsors/aljo242"],"categories":[],"sub_categories":[],"readme":"# cpp_starter_project\n\n\u003c!-- [![Build status](https://ci.appveyor.com/api/projects/status/d1tbhi2frii45rcl/branch/main?svg=true)](https://ci.appveyor.com/project/cpp-best-practices/cpp-starter-project/branch/main)--\u003e\n![CMake](https://github.com/aljo242/modern-cpp/workflows/CMake/badge.svg)\n\u003c!--  [![codecov](https://codecov.io/gh/cpp-best-practices/cpp_starter_project/branch/main/graph/badge.svg)](https://codecov.io/gh/cpp-best-practices/cpp_starter_project) --\u003e\n[![Language grade: C++](https://img.shields.io/lgtm/grade/cpp/github.com/aljo242/modern-cpp)](https://lgtm.com/projects/g/aljo242/modern-cpp/context:cpp)\n\n## Getting Started\n\n### Use the Github template\nFirst, click the green `Use this template` button near the top of this page.\nThis will take you to Github's ['Generate Repository'](https://github.com/cpp-best-practices/cpp_starter_project/generate) page.\nFill in a repository name and short description, and click 'Create repository from template'.\nThis will allow you to create a new repository in your Github account,\nprepopulated with the contents of this project.\nNow you can clone the project locally and get to work!\n\n    git clone https://github.com/\u003cuser\u003e/\u003cyour_new_repo\u003e.git\n\n### Remove frameworks you're not going to use\nIf you know you're not going to use one or more of the optional gui/graphics\nframeworks (fltk, gtkmm, imgui, etc.), you can remove them with `git rm`:\n\n    git rm -r src/\u003cunnecessary_framework\u003e\n\n## Dependencies\n\nNote about install commands:\n- for Windows, we use [choco](https://chocolatey.org/install).\n- for MacOS, we use [brew](https://brew.sh/).\n- In case of an error in cmake, make sure that the dependencies are on the PATH.\n\n\n### Too Long, Didn't Install\n\nThis is a really long list of dependencies, and it's easy to mess up.\nThat's why we have a Docker image that's already set up for you.\nSee the [Docker instructions](#docker-instructions) below.\n\n\n### Necessary Dependencies\n1. A C++ compiler that supports C++17.\nSee [cppreference.com](https://en.cppreference.com/w/cpp/compiler_support)\nto see which features are supported by each compiler.\nThe following compilers should work:\n\n  * [gcc 7+](https://gcc.gnu.org/)\n\t\u003cdetails\u003e\n\t\u003csummary\u003eInstall command\u003c/summary\u003e\n\n\t- Debian/Ubuntu:\n\n\t\t\tsudo apt install build-essential\n\n\t- Windows:\n\n\t\t\tchoco install mingw -y\n\n\t- MacOS:\n\n\t\t\tbrew install gcc\n\t\u003c/details\u003e\n\n  * [clang 6+](https://clang.llvm.org/)\n\t\u003cdetails\u003e\n\t\u003csummary\u003eInstall command\u003c/summary\u003e\n\n\t- Debian/Ubuntu:\n\n\t\t\tbash -c \"$(wget -O - https://apt.llvm.org/llvm.sh)\"\n\n\t- Windows:\n\n\t\tVisual Studio 2019 ships with LLVM (see the Visual Studio section). However, to install LLVM separately:\n\n\t\t\tchoco install llvm -y\n\n\t\tllvm-utils for using external LLVM with Visual Studio generator:\n\n\t\t\tgit clone https://github.com/zufuliu/llvm-utils.git\n\t\t\tcd llvm-utils/VS2017\n\t\t\t.\\install.bat\n\n\t- MacOS:\n\n\t\t\tbrew install llvm\n\t\u003c/details\u003e\n\n  * [Visual Studio 2019 or higher](https://visualstudio.microsoft.com/)\n\t\u003cdetails\u003e\n\t\u003csummary\u003eInstall command + Environment setup\u003c/summary\u003e\n\n\tOn Windows, you need to install Visual Studio 2019 because of the SDK and libraries that ship with it.\n\n  \tVisual Studio IDE - 2019 Community (installs Clang too):\n\n  \t  \tchoco install -y visualstudio2019community --package-parameters \"add Microsoft.VisualStudio.Workload.NativeDesktop --includeRecommended --includeOptional --passive --locale en-US\"\n\n\tPut MSVC compiler, Clang compiler, and vcvarsall.bat on the path:\n\n\t\t\tchoco install vswhere -y\n\t\t\trefreshenv\n\n\t\t\t# change to x86 for 32bit\n\t\t\t$clpath = vswhere -products * -latest -prerelease -find **/Hostx64/x64/*\n\t\t\t$clangpath = vswhere -products * -latest -prerelease -find **/Llvm/bin/*\n\t\t\t$vcvarsallpath =  vswhere -products * -latest -prerelease -find **/Auxiliary/Build/*\n\n\t\t\t$path = [System.Environment]::GetEnvironmentVariable(\"PATH\", \"User\")\n\t\t\t[Environment]::SetEnvironmentVariable(\"Path\", $path + \";$clpath\" + \";$clangpath\" + \";$vcvarsallpath\", \"User\")\n\t\t\trefreshenv\n\n\t\u003c/details\u003e\n\n\n2. [Conan](https://conan.io/)\n\t\u003cdetails\u003e\n\t\u003csummary\u003eInstall Command\u003c/summary\u003e\n\n\t- Via pip - https://docs.conan.io/en/latest/installation.html#install-with-pip-recommended\n\n\t\t\tpip install --user conan\n\n\t- Windows:\n\n\t\t\tchoco install conan -y\n\n\t- MacOS:\n\n\t\t\tbrew install conan\n\n\t\u003c/details\u003e\n\n3. [CMake 3.15+](https://cmake.org/)\n\t\u003cdetails\u003e\n\t\u003csummary\u003eInstall Command\u003c/summary\u003e\n\n\t- Debian/Ubuntu:\n\n\t\t\tsudo apt-get install cmake\n\n\t- Windows:\n\n\t\t\tchoco install cmake -y\n\n\t- MacOS:\n\n\t\t\tbrew install cmake\n\n\t\u003c/details\u003e\n\n### Optional Dependencies\n#### C++ Tools\n  * [Doxygen](http://doxygen.nl/)\n\t\u003cdetails\u003e\n\t\u003csummary\u003eInstall Command\u003c/summary\u003e\n\n\t- Debian/Ubuntu:\n\n\t\t\tsudo apt-get install doxygen\n\t\t\tsudo apt-get install graphviz\n\n\t- Windows:\n\n\t\t\tchoco install doxygen.install -y\n\t\t\tchoco install graphviz -y\n\n\t- MacOS:\n\n\t\t\tbrew install doxygen\n\t \t\tbrew install graphviz\n\n\t\u003c/details\u003e\n\n\n  * [ccache](https://ccache.dev/)\n\t\u003cdetails\u003e\n\t\u003csummary\u003eInstall Command\u003c/summary\u003e\n\n\t- Debian/Ubuntu:\n\n\t\t\tsudo apt-get install ccache\n\n\t- Windows:\n\n\t\t\tchoco install ccache -y\n\n\t- MacOS:\n\n\t\t\tbrew install ccache\n\n\t\u003c/details\u003e\n\n\n  * [Cppcheck](http://cppcheck.sourceforge.net/)\n\t\u003cdetails\u003e\n\t\u003csummary\u003eInstall Command\u003c/summary\u003e\n\n\t- Debian/Ubuntu:\n\n\t\t\tsudo apt-get install cppcheck\n\n\t- Windows:\n\n\t\t\tchoco install cppcheck -y\n\n\t- MacOS:\n\n\t\t\tbrew install cppcheck\n\n\t\u003c/details\u003e\n\n\n  * [include-what-you-use](https://include-what-you-use.org/)\n\t\u003cdetails\u003e\n\t\u003csummary\u003eInstall Command\u003c/summary\u003e\n\n\tFollow instructions here:\n\thttps://github.com/include-what-you-use/include-what-you-use#how-to-install\n\t\u003c/details\u003e\n\n#### GUI libraries\nThis project can be made to work with several optional GUI frameworks.\n\nIf desired, you should install the following optional dependencies as\ndirected by their documentation, linked here:\n\n- [FLTK](https://www.fltk.org/doc-1.4/index.html)\n- [GTKMM](https://www.gtkmm.org/en/documentation.html)\n- [QT](https://doc.qt.io/)\n\nThe following dependencies can be downloaded automatically by CMake and Conan.\nAll you need to do to install them is to turn on a CMake flag during\nconfiguration.\nIf you run into difficulty using them, please refer to their documentation,\nlinked here:\n\n- [NANA](http://nanapro.org/en-us/documentation/)\n- [SDL](http://wiki.libsdl.org/FrontPage)\n- [IMGUI](https://github.com/ocornut/imgui/tree/master/docs):\n  This framework depends on SFML, and if you are using Linux, you may need\n  to install several of SFML's dependencies using your package manager. See\n  [the SFML build tutorial](https://www.sfml-dev.org/tutorials/2.5/compile-with-cmake.php)\n  for specifics.\n\n## Build Instructions\n\nA full build has different steps:\n1) Specifying the compiler using environment variables\n2) Configuring the project\n3) Building the project\n\nFor the subsequent builds, in case you change the source code, you only need to repeat the last step.\n\n### (1) Specify the compiler using environment variables\n\nBy default (if you don't set environment variables `CC` and `CXX`), the system default compiler will be used.\n\nConan and CMake use the environment variables CC and CXX to decide which compiler to use. So to avoid the conflict issues only specify the compilers using these variables.\n\nCMake will detect which compiler was used to build each of the Conan targets. If you build all of your Conan targets with one compiler, and then build your CMake targets with a different compiler, the project may fail to build.\n\n\u003cdetails\u003e\n\u003csummary\u003eCommands for setting the compilers \u003c/summary\u003e\n\n- Debian/Ubuntu/MacOS:\n\n\tSet your desired compiler (`clang`, `gcc`, etc):\n\n\t- Temporarily (only for the current shell)\n\n\t\tRun one of the followings in the terminal:\n\n\t\t- clang\n\n\t\t\t\tCC=clang CXX=clang++\n\n\t\t- gcc\n\n\t\t\t\tCC=gcc CXX=g++\n\n\t- Permanent:\n\n\t\tOpen `~/.bashrc` using your text editor:\n\n\t\t\tgedit ~/.bashrc\n\n\t\tAdd `CC` and `CXX` to point to the compilers:\n\n\t\t\texport CC=clang\n\t\t\texport CXX=clang++\n\n\t\tSave and close the file.\n\n- Windows:\n\n\t- Permanent:\n\n\t\tRun one of the followings in PowerShell:\n\n\t\t- Visual Studio generator and compiler (cl)\n\n\t\t\t\t[Environment]::SetEnvironmentVariable(\"CC\", \"cl.exe\", \"User\")\n\t\t\t\t[Environment]::SetEnvironmentVariable(\"CXX\", \"cl.exe\", \"User\")\n\t\t\t\trefreshenv\n\n\t\t  Set the architecture using [vcvarsall](https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=vs-2019#vcvarsall-syntax):\n\n\t\t\t\tvcvarsall.bat x64\n\n\t\t- clang\n\n\t\t\t\t[Environment]::SetEnvironmentVariable(\"CC\", \"clang.exe\", \"User\")\n\t\t\t\t[Environment]::SetEnvironmentVariable(\"CXX\", \"clang++.exe\", \"User\")\n\t\t\t\trefreshenv\n\n\t\t- gcc\n\n\t\t\t\t[Environment]::SetEnvironmentVariable(\"CC\", \"gcc.exe\", \"User\")\n\t\t\t\t[Environment]::SetEnvironmentVariable(\"CXX\", \"g++.exe\", \"User\")\n\t\t\t\trefreshenv\n\n\n  - Temporarily (only for the current shell):\n\n\t\t\t$Env:CC=\"clang.exe\"\n\t\t\t$Env:CXX=\"clang++.exe\"\n\n\u003c/details\u003e\n\n### (2) Configure your build\n\nTo configure the project, you could use `cmake`, or `ccmake` or `cmake-gui`. Each of them are explained in the following:\n\n#### (2.a) Configuring via cmake:\nWith Cmake directly:\n\n    cmake -S . -B ./build\n\nCmake will automatically create the `./build` folder if it does not exist, and it wil configure the project.\n\n#### (2.b) Configuring via ccmake:\n\nWith the Cmake Curses Dialog Command Line tool:\n\n    ccmake -S . -B ./build\n\nOnce `ccmake` has finished setting up, press 'c' to configure the project,\npress 'g' to generate, and 'q' to quit.\n\n#### (2.c) Configuring via cmake-gui:\n\nTo use the GUI of the cmake:\n\n2.c.1) Open cmake-gui from the project directory:\n```\ncmake-gui .\n```\n2.c.2) Set the build directory:\n\n![build_dir](https://user-images.githubusercontent.com/16418197/82524586-fa48e380-9af4-11ea-8514-4e18a063d8eb.jpg)\n\n2.c.3) Configure the generator:\n\nIn cmake-gui, from the upper menu select `Tools/Configure`.\n\n**Warning**: if you have set `CC` and `CXX` always choose the `use default native compilers` option. This picks `CC` and `CXX`. Don't change the compiler at this stage!\n\n\u003cdetails\u003e\n\u003csummary\u003eWindows - MinGW Makefiles\u003c/summary\u003e\n\nChoose MinGW Makefiles as the generator:\n\n\u003cimg src=\"https://user-images.githubusercontent.com/16418197/82769479-616ade80-9dfa-11ea-899e-3a8c31d43032.png\" alt=\"mingw\"\u003e\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eWindows - Visual Studio generator and compiler\u003c/summary\u003e\n\nYou should have already set `C` and `CXX` to `cl.exe`.\n\nChoose \"Visual Studio 16 2019\" as the generator:\n\n\u003cimg src=\"https://user-images.githubusercontent.com/16418197/82524696-32502680-9af5-11ea-9697-a42000e900a6.jpg\" alt=\"default_vs\"\u003e\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eWindows - Visual Studio generator and Clang Compiler\u003c/summary\u003e\n\nYou should have already set `C` and `CXX` to `clang.exe` and `clang++.exe`.\n\nChoose \"Visual Studio 16 2019\" as the generator. To tell Visual studio to use `clang-cl.exe`:\n- If you use the LLVM that is shipped with Visual Studio: write `ClangCl` under \"optional toolset to use\".\n\n\u003cimg src=\"https://user-images.githubusercontent.com/16418197/82781142-ae60ac00-9e1e-11ea-8c77-222b005a8f7e.png\" alt=\"visual_studio\"\u003e\n\n- If you use an external LLVM: write [`LLVM_v142`](https://github.com/zufuliu/llvm-utils#llvm-for-visual-studio-2017-and-2019)\n under \"optional toolset to use\".\n\n\u003cimg src=\"https://user-images.githubusercontent.com/16418197/82769558-b3136900-9dfa-11ea-9f73-02ab8f9b0ca4.png\" alt=\"visual_studio\"\u003e\n\n\u003c/details\u003e\n\u003cbr/\u003e\n\n2.c.4) Choose the Cmake options and then generate:\n\n![generate](https://user-images.githubusercontent.com/16418197/82781591-c97feb80-9e1f-11ea-86c8-f2748b96f516.png)\n\n### (3) Build the project\nOnce you have selected all the options you would like to use, you can build the\nproject (all targets):\n\n    cmake --build ./build\n\nFor Visual Studio, give the build configuration (Release, RelWithDeb, Debug, etc) like the following:\n\n    cmake --build ./build -- /p:configuration=Release\n\n\n### Running the tests\n\nYou can use the `ctest` command run the tests.\n\n```shell\ncd ./build\nctest -C Debug\ncd ../\n```\n\n## Troubleshooting\n\n### Update Conan\nMany problems that users have can be resolved by updating Conan, so if you are\nhaving any trouble with this project, you should start by doing that.\n\nTo update conan:\n\n    pip install --user --upgrade conan\n\nYou may need to use `pip3` instead of `pip` in this command, depending on your\nplatform.\n\n### Clear Conan cache\nIf you continue to have trouble with your Conan dependencies, you can try\nclearing your Conan cache:\n\n    conan remove -f '*'\n\nThe next time you run `cmake` or `cmake --build`, your Conan dependencies will\nbe rebuilt. If you aren't using your system's default compiler, don't forget to\nset the CC, CXX, CMAKE_C_COMPILER, and CMAKE_CXX_COMPILER variables, as\ndescribed in the 'Build using an alternate compiler' section above.\n\n### Identifying misconfiguration of Conan dependencies\n\nIf you have a dependency 'A' that requires a specific version of another\ndependency 'B', and your project is trying to use the wrong version of\ndependency 'B', Conan will produce warnings about this configuration error\nwhen you run CMake. These warnings can easily get lost between a couple\nhundred or thousand lines of output, depending on the size of your project.\n\nIf your project has a Conan configuration error, you can use `conan info` to\nfind it. `conan info` displays information about the dependency graph of your\nproject, with colorized output in some terminals.\n\n    cd build\n    conan info .\n\nIn my terminal, the first couple lines of `conan info`'s output show all of the\nproject's configuration warnings in a bright yellow font.\n\nFor example, the package `spdlog/1.5.0` depends on the package `fmt/6.1.2`.\nIf you were to modify the file `conanfile.py` so that it requires an\nearlier version of `fmt`, such as `fmt/6.0.0`, and then run:\n\n```bash\nconan remove -f '*'       # clear Conan cache\nrm -rf build              # clear previous CMake build\ncmake -S . -B ./build     # rebuild Conan dependencies\nconan info ./build\n```\n\n...the first line of output would be a warning that `spdlog` needs a more recent\nversion of `fmt`.\n\n## Testing\nSee [Catch2 tutorial](https://github.com/catchorg/Catch2/blob/master/docs/tutorial.md)\n\n## Fuzz testing\n\nSee [libFuzzer Tutorial](https://github.com/google/fuzzing/blob/master/tutorial/libFuzzerTutorial.md)\n\n\n## Docker Instructions\n\nIf you have [Docker](https://www.docker.com/) installed, you can run this\nin your terminal, when the Dockerfile is in your working directory:\n\n```bash\ndocker build --tag=my_project:latest .\ndocker run -it my_project:latest\n```\n\nThis command will put you in a `bash` session in a Ubuntu 18.04 Docker container,\nwith all of the tools listed in the [Dependencies](#dependencies) section already installed.\nAdditionally, you will have `g++-10` and `clang++-11` installed as the default\nversions of `g++` and `clang++`.\n\nIf you want to build this container using some other versions of gcc and clang,\nyou may do so with the `GCC_VER` and `LLVM_VER` arguments:\n\n```bash\ndocker build --tag=myproject:latest --build-arg GCC_VER=9 --build-arg LLVM_VER=10 .\n```\n\nThe CC and CXX environment variables are set to GCC version 10 by default.\nIf you wish to use clang as your default CC and CXX environment variables, you\nmay do so like this:\n\n```bash\ndocker build --tag=my_project:latest --build-arg USE_CLANG=1 .\n```\n\nYou will be logged in as root, so you will see the `#` symbol as your prompt.\nYou will be in a directory that contains a copy of the `cpp_starter_project`;\nany changes you make to your local copy will not be updated in the Docker image\nuntil you rebuild it.\nIf you need to mount your local copy directly in the Docker image, see\n[Docker volumes docs](https://docs.docker.com/storage/volumes/).\nTLDR:\n\n```bash\ndocker run -it \\\n\t-v absolute_path_on_host_machine:absolute_path_in_guest_container \\\n\tmy_project:latest\n```\n\nYou can configure and build [as directed above](#build) using these commands:\n\n```bash\n/starter_project# mkdir build\n/starter_project# cmake -S . -B ./build\n/starter_project# cmake --build ./build\n```\n\nYou can configure and build using `clang-11`, without rebuilding the container,\nwith these commands:\n\n```bash\n/starter_project# mkdir build\n/starter_project# CC=clang CXX=clang++ cmake -S . -B ./build\n/starter_project# cmake --build ./build\n```\n\nThe `ccmake` tool is also installed; you can substitute `ccmake` for `cmake` to\nconfigure the project interactively.\nAll of the tools this project supports are installed in the Docker image;\nenabling them is as simple as flipping a switch using the `ccmake` interface.\nBe aware that some of the sanitizers conflict with each other, so be sure to\nrun them separately.\n\nA script called `build_examples.sh` is provided to help you to build the example\nGUI projects in this container.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faljo242%2Fmodern-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faljo242%2Fmodern-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faljo242%2Fmodern-cpp/lists"}