| 1 | \page install-windows-clion-vcpkg Building a Discord Bot using CLion & VCPKG (Windows) |
| 2 | |
| 3 | \warning This page is for **Windows only**. If you want to use CLion on Linux, look to use \ref build-a-discord-bot-linux-clion "this page". Like always with windows, we highly recommends you use the [pre-made Visual Studio template](https://github.com/brainboxdotcc/windows-bot-template/). This tutorial also assumes you have installed D++ via VCPKG already. If you haven't, look at \ref install-vcpkg "this page". |
| 4 | |
| 5 | ### Changing Toolchains |
| 6 | |
| 7 | \note If you have already configured your toolchain to use anything **but** MinGW64, then you can skip to the next section. Otherwise, it is **critical** that you follow along with this section. It should also be noted that you **need** Visual Studio for this. |
| 8 | |
| 9 | Head on over to `File > Settings` (Ctrl+Alt+S), then navigate to `Build, Execution, Deployment > Toolchains`. |
| 10 | |
| 11 | If there is a Visual Studio toolchain there, drag it to the top of the list. This will make the Visual Studio toolchain the default toolchain. |
| 12 | |
| 13 | \image html clionvstoolchain.png |
| 14 | |
| 15 | If you don't have the Visual Studio toolchain, you can hit the plus symbol above the list of toolchains and add a toolchain. This is also how you can add WSL as a toolchain! |
| 16 | |
| 17 | \image html clionvstoolchain2.png |
| 18 | |
| 19 | From there, you need to drag it to the top (if it didn't already add at the top) to ensure it's the default toolchain. |
| 20 | |
| 21 | ### Using VCPKG with CLion |
| 22 | |
| 23 | To use vcpkg in CLion, add the following line to your CMake options in the settings (Located under `Settings > Build, Execution, Deployment > CMake`) |
| 24 | ```cmd |
| 25 | -DCMAKE_TOOLCHAIN_FILE=path_to_vcpkg_root_folder/scripts/buildsystems/vcpkg.cmake |
| 26 | ``` |
| 27 | For example, if your root folder is `C:/vcpkg/` then the CMake option will be: |
| 28 | ```cmd |
| 29 | -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake |
| 30 | ``` |
| 31 | |
| 32 | ### Making a test application. |
| 33 | |
| 34 | Open your `main.cpp` file and then copy and paste the following \ref firstbot "example program" in. Then, set your bot token (see \ref creating-a-bot-application). Here's how your `main.cpp` file should look: |
| 35 | |
| 36 | \include{cpp} firstbot.cpp |
| 37 | |
| 38 | If everything went well, you should now have a functioning bot! If not, feel free to ask us on the D++ [discord server](https://discord.gg/dpp). |
| 39 | |
| 40 | ### Troubleshooting |
| 41 | |
| 42 | If you see a message like `Detecting C compiler ABI info - failed` or something along the lines of `"cl.exe" is not able to compile a simple test program`, then try to reinstall `Windows Build Tools` along with the `Windows SDK` from the Visual Studio Installer. |