0

I am trying to install fmtlib and I have downloaded the zip folder and extracted it, what do I do next to use it in my Visual Studio 2022 project? Because it's my first time installing an external library. Im using windows 10.

Felierix
  • 179
  • 3
  • 12

4 Answers4

4

Once you have downloaded and extracted the fmtlib, Open Visual Studio and create new project New Project -> Console App replace the application file where main method is present with below code.

First line (#define FMT_HEADER_ONLY) is mandatory, which tells compiler to compile fmt header file also.

#define FMT_HEADER_ONLY
#include <iostream>
#include <fmt/color.h>
int main()
{
    std::cout << "Hello World!\n";
    fmt::print(fmt::emphasis::bold | fg(fmt::color::red),
        "Elapsed time: {0:.2f} seconds", 1.23);
}

Go to Properties of project Properties, and click on dropdown of Include Directories as shown in screenshot.

Click on New Line folder Folder Icon and click on line to edit and browse folder path of include directory (C:\Users\username\Downloads\fmt-8.1.0\fmt-8.1.0\include)Browse till include directory of fmt lib.

Cross check the path is added Confirm.

Now build the Project and Execute code. Colorful Text Output

Happy Coding!

  • Maybe it's better to specify the define in the compiler command line with `/DFMT_HEADER_ONLY`. However I'd avoid to recompile the library each time. – MatG Oct 04 '22 at 08:50
1

First, you have to build the lib with CMake, then you will get the .lib files. Then you simply add the Header files in the include folder to your project in Visual Studio and link the .lib files to your project like here described:

How to add additional libraries to Visual Studio project?

JonBai03
  • 11
  • 2
  • How to build the library is also described on the website of the library itself: https://fmt.dev/latest/usage.html – JonBai03 Jan 04 '22 at 14:32
0

I believe fmtlib is header only. You can just add the unzipped folder to your includes.

0

If you enable C++ latest as your C++ Language Standard (latest) in properties, C++, language, you don't need fmtlib.