Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Using the fmt library is problematic
QtWS25 Last Chance

Using the fmt library is problematic

Scheduled Pinned Locked Moved Unsolved 3rd Party Software
4 Posts 3 Posters 2.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Frenchy
    wrote on last edited by
    #1

    Hello!

    First steps in C++ (with Qt Creator as IDE) are disappointing.

    The book states that if "format" is absent (Apple clang version 15.0.0), it can be replaced by the "fmt" library available at this address:
    https://github.com/fmtlib/fmt

    Unfortunately, none of the tests are conclusive regarding the integration of this component into the structure of the project file.
    With this simple code...

    #include <iostream>
    #include "fmt-master/include/fmt/format.h"
    using namespace std;
    using namespace fmt;
    
    int main()
    {
        string theCar{"My car"};
        int price{10000};
        cout << format("{} costs {} USD\n", theCar, price);
        return 0;
    }
    

    ...I get these error messages:

    *By not providing "Findfmt.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "fmt", but CMake did not find one. Could not find a package configuration file provided by "fmt" with any of the following names: fmtConfig.cmake fmt-config.cmake Add the installation prefix of "fmt" to CMAKE_PREFIX_PATH or set "fmt_DIR" to a directory containing one of the above files. If "fmt" provides a separate development package or SDK, be sure it has been installed.

    Included header format.h is not used directly (fix available)*

    Can anyone explain to me how to use "fmt"?
    Sorry for not understanding...
    Thanks for your help.

    CMakeLists.txt is set as follows:

    cmake_minimum_required(VERSION 3.14)
    
    project(fmt_B LANGUAGES CXX)
    
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    
    set(CMAKE_CXX_STANDARD 20)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
    find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
    
    add_executable(fmt_B
      main.cpp
      fmt.cc format.cc os.cc
    )
    find_package(fmt REQUIRED)
    target_link_libraries(fmt_B/fmt-master/include/fmt Qt${QT_VERSION_MAJOR}::Core)
    
    include(GNUInstallDirs)
    install(TARGETS fmt_B
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    )
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Are you following these instructions ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      F 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Are you following these instructions ?

        F Offline
        F Offline
        Frenchy
        wrote on last edited by
        #3

        @SGaist
        I will look at it...
        Thank you for the link.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SimonSchroeder
          wrote on last edited by
          #4

          The fmt library also has a header-only mode. It is enabled by providing a define FMT_HEADER_ONLY. In this case you don't need to link to the fmt library anymore. The only requirement is then to have the path to the headers in your search path. (BTW, if everything is set up correctly, you most likely have to just write #include "fmt/format.h". The path up to this point should be set up differently.)

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved