Setting up your development environment is not a quick task, but if done right it can save you hundreds of hours.
Example, compiling Cppcheck with cmake: mkdir build cd build cmake. If you want to compile the GUI you can use the flag.
- Cppcheck is a static analysis tool for C/C code. It provides unique code analysis to detect bugs and focuses on detecting undefined behaviour and dangerous coding constructs. The goal is to have very few false positives. Cppcheck is designed to be able to analyze your C/C code even if it has non-standard syntax (common in embedded projects).
- Cppcheck is an analysis tool for C/C code. It provides unique code analysis to detect bugs and focuses on detecting undefined behaviour and dangerous coding constructs. The goal is to detect only real errors in the code, and generate as few false positives (wrongly reported warnings) as possible.
My preferred development environment for C++ is CLion running on Mac. I have also included details of my Windows development environment since lots of people use Windows. Visual Studio, Eclipse and other IDEs have similar features to CLion, so modify the instructions as needed to get the same functionality.
CLion relies on external programs for compilation which means you need to have g++ and gcc already installed. There are multiple options (MinGw, Cygwin, etc) but my preferred one is Msys2 which provides a unix like environment under Windows. It also helps install additional programs easily.
- Right Click on Start > System > Search for View Advanced System Settings > Environment Variables, Add new user variable HOME with %USERPROFILE% - this will make Msys2 start in the windows directory (if you do this after installing Msys2, move files from C:msys64homepisan to C:Userspisan manually https://github.com/valtron/llvm-stuff/wiki/Set-up-Windows-dev-environment-with-MSYS2
- Install Git for Windows https://git-scm.com/downloads
- Install MSys2 https://www.msys2.org/ on default directory C:msys64 Follow the instructions on the web page, especially about 'pacman -Syu' to update package database and core system
- pacman -S --needed mingw-w64-x86_64-emacs mingw64/mingw-w64-x86_64-gcc python3 mingw64/mingw-w64-x86_64-putty mingw64/mingw-w64-x86_64-cmake mingw-w64-x86_64-toolchain mingw64/mingw-w64-x86_64-cppcheck msys/unzip python3-pip mingw32/mingw-w64-i686-make msys/git
- pip install --upgrade pip
- pip install cpplint
- Run c:msys64mingw64.exe to get started and pin it to the taskbar for future
- Make sure the compilers are installed, try 'which g++' to find the location of g++
- You can configure Putty under Windows as well as ssh under Msys2 to use public/private keys to allow login without using password. Run C:Program FilesPuTTYputtygen.exe to generate a private key. Save it to your windows machine. Copy the 'public key' (starts with ssh-rsa ..). On the linux server, such as uw1-320-01.uwb.edu, edit the file ~/.ssh/authorized_keys and paste the 'public key' to this file. Configure Putty on windows to use your netid as the auto-login username (under Connection > Data) and Connection > SSH > Auth should have the private key file for authentication. You can now login to uw1-320-01 without entering a password. Repeat editing the authorized_keys file for each of the CSS Linux machines as needed.
Cmake Cppcheck Output
Mac relies on Xcode for compilers or you can install g++ and gcc via brew
- Install Xcode -- we need it for the command line tools
- Start XCode and agree to Terms and Conditions
- Open terminal use: 'xcode-select --install' This will install comman-line interface (CLI)
- Install homebrew
- Open terminal use: brew install valgrind cppcheck gcc make cmake emacs gdb wget python3
- pip3 install cpplint
Install CLion, assuming Msys2 has already been set as above for Windows or necessary programs installed for Mac
- Settings > Editor > Live Templates > CMake -- create a new shortcut named 'wall' as follows
- Clion add plugins cpplint and cppcheck
- Configure cppcheck
Cppcheck should give a warning for 'int *x = new int;' indicating memory leak
- set cppcheck options
--enable=all --inconclusive --language=c++ --std=posix --suppress=missingIncludeSystem
- python C:msys64usrbinpython.exe and cpplint at C:msys64usrlibpython3.7site-packagescpplint.py ( setting it to C:msys64usrbincpplint is reported not to work)
- Cpplint should give a warning about no copyright message found at the top of file
- set cpplint options (can also create a file CPPLINT.cfg in the project):
- g++ for regular Windows development
- wsl for compiling thinghs under ubuntu and using valgrind
- Visual Studio's compiler -- if necessary
- Download gitignore for JetBrains.CLion from https://github.com/github/gitignore/tree/master/Global and save it to ~/.gitignore_global
- File > Settings > Plugins -- enable GitHub and Git Integration plugins
- File > Settings > Version Control > GitHub -- add your github account
- File > Settings > Version Control > Git -- add executable to git program, something like c:msys64usrbingit.exe
- Confirm that cpplint and cppcheck are working from CLion
- Confirm that Using VCS menu option, files can be committed and pushed to repository
- If you have installed WSL (Windows Subsystem for Linux)
- Follow instructions on https://www.jetbrains.com/help/clion/how-to-use-wsl-development-environment-in-clion.html and https://blog.jetbrains.com/clion/2018/01/clion-and-linux-toolchain-on-windows-are-now-friends/ to setup ubuntu-clion connection
- sudo apt-get install cmake gcc clang gdb build-essential
- wget https://raw.githubusercontent.com/JetBrains/clion-wsl/master/ubuntu_setup_env.sh && bash ubuntu_setup_env.sh
Windows - New Computer
Getting a new Windows computer ready.
Cppcheck Visual Studio
For some reason a new Windows computrer comes with all types of unnecessary stuff. These are all the steps I had to take to get my computer into a usable state. Some of them may be applicable to you.
- IMPORTANT. By default Windows Explorer hides file extensions. While this might be OK for a regular user, it is a nightmare for a developer where you enddp with multiple files with the same name: Readme.txt (a text file that can be opened and edited in Notepad or any text editor), Readme.pdf (PDF file that can be opened in Acrobat), Readme.exe (an executable file, can be run by double clicking, an unusual name for a program), README.cfg (probably a configuration file), Readme.md (a markdown file, can be edited by any text editor), ..
Show file extensions - Search for “file explorer options” under Windows Setting from Start button. Full path in title bar, Uncheck hide extensions
- Download install Huskey OnNet. You need this to connect to CSS Linux Labs when you are not on the UW network. https://itconnect.uw.edu/connect/uw-networks/about-husky-onnet/
- Install basic version of FileZilla. Need this to transfer files to CSS Linux Labs. https://filezilla-project.org/download.php?type=client
- Uninstall Dell Mobile Connect, Candy Crush, Microsoft News, Minecraft, Netflix, weather, Xbox, Xbox Game Speech Windows, Xbox Live, Dropbox Promotion, Fitbit Coach, LinkedIn, Solitaire Collection, Mobile Plans
- Create a second admin account - eventually make this account a regular account and use the admin account when installing new software is required
- Windows Update - if you need it
- Add c:Userspisan to Quick Access in File Explorer
- Right Click on Start > System > Search for View Advanced System Settings > Advanced > Visual Effects -- modify as needed
- Right Click on Start > System > Search for View Advanced System Settings > Computer Name - somename -- need to reboot after this
- Create a restore point, Search “restore point”, allocate 1-2% for System, and create the first restore point
- Turn off Right Click on Start > System > Search for View Advanced System Settings > Remote Assistance
- (Search) Notifications and Actions, Disable most notifications
- Kill apps on shutdown - maybe, https://www.tomshardware.com/picturestory/853-windows-10-settings-you-should-change.html#s4
- Themes - set theme, back to colors to set the default color to blue rather than switching with theme/background
- Taskbar - remove people
- Sign-in options, create a pin
- Do not 'Use my sign-in to automatically finish setting up my device and reopen my apps after an update or restart.'
- Privacy - turn it all off
- Wifi - turn off 2.0, turn off allow another device to turn mobile hotspot on
- Video Playback - optimize for movie quality. If I am watching a movie, I’ll eventually plug things in
- Cortana - my cloud content off, device history off, no cortana on locked screen
- No web search from Cortane/local search - https://www.thewindowsclub.com/disable-web-search-in-windows-10 (did not work for me, testing https://pureinfotech.com/disable-cortana-windows-10/ via regedit)
- Disable onedrive starting at startup - from Task Manager, revisit later
- Turn off - account info for apps
- Turn off - apps accessing contacts, calendar, call history, tasks, email, text messages, radios, other devices, feedback and diagnostics
- Minimize background apps
- Don’t let apps access diagnostic info
- Automatic downloads off
- Start > Live Tiles, right click on each one and unpin from start. Once all the tiles are gone, use a mouse or trackpad to drag the right edge of Start all the way to the left.
- Settings > Personalization > Start - show app list on start menu
- Download programs
- Chrome -- set as default browser, sync settings
- Add a new person to chrome, UW
- Install Google Drive Stream for UW account
- Install Office 365 - UW subscription
- Install Visual Studio Community - project properties > c++ > precompiled headers - not using them. Remove pch.h and cpp
- Install Adobe Acrobat DC
- Install Microsoft Subsystem for Linux (WSL) such as Ubuntu from Windows Store https://www.microsoft.com/en-us/p/ubuntu/9nblggh4msv6?activetab=pivot:overviewtab
- sudo apt-get update
- sudo apt install g++, git, python3, python3-pip, cmake, cppcheck, emacs25, valgrind, cmake, gdb
- pip install cpplint
- Ubuntu can edit Windows files by accessing /mnt/c but Windows cannot access Ubuntu files -- learned it the hard way!
- Install CodeBlocks -- toolchain executables is in C:msys64mingw64bin
- Download Unity Hub
- github for desktop
- Pin to Taskbar: Chrome, Emacs, Msys2, putty, powershell
- For emacs, edit properties to start runemacs from C:msys64mingw64bin. Change emacs start directory to be c:
- For Msys2, edit properties to run C:msys64msys2_shell.cmd
CherrySim uses Cppcheck, a static code analysis tool that helps us to spot common coding errors quickly.
Cppcheck is used in our pipeline. For the most accurate results for the internal development environment, it is recommended to do small commits often so that the pipeline spots error as soon as possible. If you want to execute Cppcheck locally however, you have the following options (both have limitations, see below):
(Recommended) Use the CMake GUI to analyze the Visual Studio Solution.
cppcheck.cppcheckinside your Fruitymesh repository
All occurrences of
PATH_TO_CMAKE_DIRECTORYmust be replaced with your CMake build directory. For example,
All occurrences of
PATH_TO_FRUITYMESH_REPOSITORYmust be replaced with the path of the Fruitymesh Repository. For example,
Open the CppCheck GUI
Make sure that the following is ticked: Edit → Preferences → General → 'Enable inline suppressions'
File → Open Project File → Select the modified cppcheck.cppcheck
If asked if the build dir should be created, click 'Yes'
Cppcheck now scans the repository. This might take some time.
(Advanced) Use CMake to execute Cppcheck on Windows.
According to the CMake docs, this is only supported with Makefile and Ninja Generators but will produce the closest result to the one of our pipeline. Cppcheck must be placed in your PATH variable.
Download and install clang 9.0 32-bit (part of LLVM). We highly recommend not changing the default installation path so you can directly use the commands down below as they are.
Create a sibling directory next to the Fruitymesh repository
Download boxcryptor. Inside that directory execute the following command in a terminal:
cmake ./fruitymesh -G 'Unix Makefiles' -DFORCE_CPPCHECK=ON -D CMAKE_C_COMPILER='C:/Program Files (x86)/LLVM/bin/clang.exe' -D CMAKE_CXX_COMPILER='C:/Program Files (x86)/LLVM/bin/clang++.exe'. If you changed the default installation path of clang, replace the values of
CMAKE_CXX_COMPILERto the paths to clang on your machine.
Execute the following and look out for the occurring warnings:
cmake --build .
Both approaches don’t mimic the behavior of the pipeline exactly, so both have the potential to show some warnings that are not on the pipeline and vice versa.